Questions tagged [waitpid]

The `waitpid()` function is a POSIX function designated for waiting for status changes and for obtaining the status information about the child process whose status has changed.

The waitpid() function is a POSIX function designated for waiting for status changes and for obtaining the status information about the child process whose status has changed.

Being used together with the fork() function, the waitpid()function allows to take control over the child process status changes in a variety of ways. The function behavior is very flexible and depends on parameters passed to the function arguments. However, exists another way to deal with the child process status changes ignoring them. This can be achieved by ignoring the SIGCHLD signal, delivered by the kernel to the parent process when a child process terminates or stops.

299 questions
0
votes
0 answers

Understanding a reentrant parent function that waits on a child process in a non-blocking manner

I have some C++ code running on Linux in which a re-entrant, bool returning, parent process forks a child process (of course only once), and then uses waitpid to check the exit status of said child process. If the child process is complete then it…
Mr B
  • 3
  • 3
0
votes
0 answers

How can I implement background & PID in my own shell in C?

Good afternoon, I'm a student, and I'm trying to create my own shell in C, so far I've gotten it to do everything I need correctly but I'm looking for a way to implement asynchronous synchronization when typing & behind a statement or command (Also…
Michael Bueno
  • 33
  • 1
  • 1
  • 5
0
votes
1 answer

Minishell background

I am doing a minishell project for college, and I don't know how to execute commands in background. The one thing i know is that i have to use waitpid() and sigaction(), but i don't know how. If somebody would give me a hand with this i will be…
0
votes
1 answer

Fork off more processes as previous finish, until max is reached

To fork off X processes and have the parent wait for all, I have the following code: int maxProcesses = 10; for (int currentChild = 0; currentChild < maxProcesses; currentChild++) { pid_t pid = fork(); if (pid < 0) { // Error }…
Ali
  • 558
  • 7
  • 28
0
votes
3 answers

Proper way to retrieve return value of wait command

I have the following code in a bash script: for job in `jobs -p`; do echo "PID => ${job}" if ! wait ${job} ; then echo "At least one test failed with exit code => $?" ; EXIT_CODE=1; fi done wait , in this case, wait…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
1 answer

Process wait using linux system call wait

I am trying to create a process using fork system call and then wait on the child process. I have used the following: waitpid (pid, &status, 0); 1) The first problem is that the status is 8 bit shifted to the left e.g., if the child process returns…
user2277648
  • 121
  • 2
  • 7
0
votes
1 answer

waitpid() function time-out in seconds

I have write this code: static int exec_prog(const char **argv) { pid_t my_pid; int status, timeout /* unused ifdef WAIT_FOR_COMPLETION */; if (0 == (my_pid = fork())) { if (-1 == execve(argv[0], (char **)argv , NULL)) { …
LIMA
  • 125
  • 1
  • 1
  • 8
0
votes
1 answer

How to check if a process is waiting due to call to wait() or waitpid()?

I see that in sys_wait4 (that is reached through calls to wait() or waitpid()) we insert the current process into a special queue that is saved in its struct task: DECLARE_WAITQUEUE(wait, current); …
Mano Mini
  • 607
  • 4
  • 15
0
votes
1 answer

For waitpid, how do I know if the child finishes its process?

First, I fork a child to do something, and I use waitpid(-1, &child_status, WNOHANG); in the parent to let parent continue instead of waiting for child to finish. How do I know when the child finished its process?
Jam
  • 113
  • 2
  • 7
0
votes
2 answers

C - Create 3 child processes with fork()

I want to create exactly 3 child processes with fork(). Here is my code to create one child process: #include #include #include void main(){ int pid = fork(); if(pid < 0){ /* was not successfully */ …
Nono
  • 1,073
  • 4
  • 23
  • 46
0
votes
1 answer

execvp fork : wait for stdout

I'm coding a simple linux shell in C. Sometimes when using fork and then executing a NON-BLOCKING command - my next printf disappear. I'm guessing it is because the child process is writing to stdout. If I use waitpid there is no problem - because…
Daniel
  • 13
  • 4
0
votes
2 answers

waitpid - difference between first parameter pid=-1 and pid=0

I am reading http://www.tutorialspoint.com/unix_system_calls/waitpid.htm regarding the waitpid function. It says this about the first parameter, pid, -1 meaning wait for any child process. 0 meaning wait for any child process whose process…
Old Geezer
  • 14,854
  • 31
  • 111
  • 198
0
votes
1 answer

Systems programming: wait(&status)'s return value

While learning about forking and piping, I came across the following excellent tutorial: https://www.cs.rutgers.edu/~pxk/416/notes/c-tutorials/pipe.html However, the tutorial goes into discussing how one can establish a pipe between 2 child…
nirvanaswap
  • 859
  • 2
  • 11
  • 21
0
votes
1 answer

fork() and waitpid() not waiting for child

I am having a bit of trouble getting waitpid to work could someone please explain what is wrong with this code? #include #include #include using namespace std; int main() { string filename_memory; …
Curious
  • 20,870
  • 8
  • 61
  • 146
0
votes
1 answer

waitpid(pid,status,0) status not reading correctly

everyone. I've got a problem that is making me very confused. I'm just trying to print out the status received from a terminated process but it isn't working the way I thought it would. Here is the code. int main(int argc, char *argv[]) { …
Paul Myers
  • 41
  • 1
  • 1
  • 6