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

How to use waitpid when execv returns an error?

My program loops through a vector of strings and runs a program to do some work. Each entry in the vector has its own associated program. The child processes are created using fork() and execv() in the loop. The parent process is waiting until each…
Siedler
  • 77
  • 1
  • 12
0
votes
0 answers

waitpid() returns Unknown error in a certain case

I created parent process and child process. And then from the child process, I created 3 more grand child processes. From child process, SIGTERM is sent to the grand child processes and wait the grand child process terminated using…
Cprogrammer
  • 153
  • 9
0
votes
0 answers

Not able to receive 'Continued' status from waitpid using the nix crate

I'm experimenting with the nix crate in order to debug child processes. I would like to receive events when the child process stops, continues and exits. Stoppages and exits are reported using the waitpid function. I'm having trouble receiving the…
rempas
  • 123
  • 1
  • 7
0
votes
1 answer

Create multiple processes using fork and wait

I am trying to write a program which will create processes as follows : P1 -> P2 -> P3 P1-> P4 ->P5 P2, P3 need to be finished before P4, P5 my code so far : #include int main() { for(int i=0;i<2;i++) // loop will run 2 times …
2014GAM
  • 103
  • 1
  • 9
0
votes
0 answers

how can i make the parent start working when the child process paused? c programming

I tried to use waitpid, but I'm stuck at how can I achieve that. because i want to kill(childID, SIGCONT); from the parent and make the child do something without kalling it (with continue) but rather stop it and when i "child is stopped" the…
0
votes
0 answers

waitpid() always returns '-1'

I got an assignment to make unix-like shell in C. The user can input "procs" which prints all running processes, and before executing this function, I must use the function "updateProcessList" which traverses the list of processes and with the help…
Max
  • 1
  • 1
0
votes
1 answer

C++ waiting for process to finish multiple times?

Help me correct my confusion, I have a job running in bg with pid = 3 I want to check if it has finished every 10 sec (non blocking) and print hello once and stop; But someone claimed the following: this won't work as status can be consumed only…
user15728444
0
votes
0 answers

fork/vfork, exec and waitpid in atomic way

Let suppose that process-A calls fork pid = fork(); ... waitpid( pid, ...); Is it possible, that between these calls (fork and waitpid) proccess-B, which is created by fork(), may to finish? Then some new process-C starts and gets a pid…
Павел
  • 113
  • 7
0
votes
1 answer

c - does waitpid() and co detect child termination only when all children are terminated?

I am writing this question with a bit of a confusion as i feel that I'm missing some point (that's why I am writing it, after all). So i've been studying how multiple processes access a single file. I have a basic code that makes fork two times -…
Anton Tretyakov
  • 303
  • 1
  • 9
0
votes
0 answers

Monitoring all the child processes in C

I have a question regarding process management in Unix. Let's say I have a C program "main" which forks a child and wait for the child to finish using waitpid sys call. The child process calls a script "test". The script "test" forks a child and…
nik
  • 23
  • 1
  • 4
0
votes
1 answer

if I use waitpid() after kill() with SIGTERM my program does not behave how its supposed. But it works if I dont use waitpid()?

Im trying to close a receiver on a RPC client that is running on a child process giving it max. 5 seconds to finish its business. If I do it while using waitpid() to ensure the child process terminated gracefully after using SIGTERM, I can no longer…
GeeCode
  • 21
  • 2
  • 10
0
votes
1 answer

Unable to exit loop after reading using two pipes in C (processes)

I have taken a look at this and also this stack overflow links. I am having trouble understanding the process for closing write ends of pipes. In the code below, I have 3 processes, one parent, a child of the parent, and a child of the child. I am…
0
votes
1 answer

waitpid(WNOHANG) returns 0 even though child process should have terminated

I have a function which uses fork(), dup2() and execvpe() to execute some external application, and provide 3 pipes to its standard file descriptors (stdin, stdout and stderr). After the function returns, the parent will use those pipes to write()…
Felix G
  • 674
  • 1
  • 7
  • 17
0
votes
0 answers

Check whether child process terminated in C

waitpid(-1, NULL, 0) stops the calling process until one of its children changes status (so not necessarily terminated). I want to check after calling waitpid(-1, NULL, 0), whether a specific child terminated, I'm doing this by using…
tonik
  • 465
  • 1
  • 4
  • 15
0
votes
1 answer

Is this interpretation of signals correct?

We are in a parent process, and pid holds the child process ID. My question is, in this piece of code, are we just waiting for a stopped(WUNTRACED) / resumed(WCONTINUED) signal for the child process? Or we can accept a kill/stop signal as…
B.Castarunza
  • 135
  • 12