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
63
votes
10 answers

Bash: wait with timeout

In a Bash script, I would like to do something like: app1 & pidApp1=$! app2 & pidApp2=$1 timeout 60 wait $pidApp1 $pidApp2 kill -9 $pidApp1 $pidApp2 I.e., launch two applications in the background, and give them 60 seconds to complete their work.…
user1202136
  • 11,171
  • 4
  • 41
  • 62
41
votes
2 answers

waitpid, wnohang, wuntraced. How do I use these

I am a bit confused. As I understand, waitpid with a pid of -1 means that I wait for all child's to finish but if I add an option to the waitpid of WNOHANG, that options says to exit immediately if none have finished...These seems extremely…
8this
  • 485
  • 1
  • 5
  • 9
36
votes
3 answers

Example of waitpid() in use?

I know that waitpid() is used to wait for a process to finish, but how would one use it exactly? Here what I want to do is, create two children and wait for the first child to finish, then kill the second child before exiting. //Create two…
user3063864
  • 661
  • 2
  • 7
  • 18
31
votes
1 answer

wait3 (waitpid alias) returns -1 with errno set to ECHILD when it should not

Context is this Redis issue. We have a wait3() call that waits for the AOF rewriting child to create the new AOF version on disk. When the child is done, the parent is notified via wait3() in order to substitute the old AOF with the new one. However…
antirez
  • 18,314
  • 5
  • 50
  • 44
15
votes
5 answers

Why does wait() set status to 255 instead of the -1 exit status of the forked process?

I'm trying to return an integer value from a child process. However, if I use exit(1) I get 256 as the output from wait(). Using exit(-1) gives 65280. Is there a way I can get the actual int value that I send from the child…
user191776
11
votes
4 answers

Reaping child processes from Perl

I have a script that spawns a set of children. The parent must wait for each of the children to finish. My script performs similar to the following perl script: #! /usr/bin/perl use strict; use warnings; print "I am the only process.\n"; my…
EMiller
  • 2,792
  • 4
  • 34
  • 55
10
votes
1 answer

Return code when OOM killer kills a process

I am running a multiprogrammed workload (based on SPEC CPU2006 benchmarks) on a POWER7 system using SUSE SLES 11. Sometimes, each application in the workload consumes a significant amount of memory and the total memory footprint exceeds the…
betabandido
  • 18,946
  • 11
  • 62
  • 76
10
votes
1 answer

Determine pid of terminated process

I'm trying to figure out what the pid is of a process that sent the SIGCHLD signal, and I want to do this in a signal handler I created for SIGCHLD. How would I do this? I'm trying: int pid = waitpid(-1, NULL, WNOHANG); because I want to wait for…
Hristo
  • 45,559
  • 65
  • 163
  • 230
10
votes
2 answers

Using waitpid to run process in background?

I am trying to mimic the bash feature of running process in the background if "&" is found at the end of the command. I have the following function...and I don't think it's doing what I want it to do int execute(char* args[],int background,int…
user1411893
  • 608
  • 2
  • 8
  • 19
9
votes
1 answer

Why doesn't waitpid wait for the process to exit?

In the below script I am trying to figure out how waitpid works, but it doesn't wait for ssh process to exit. done is printed right away and not after the ssh process exists. Question How to I make waitpid only continue when the pid I give it have…
Jasmine Lognnes
  • 6,597
  • 9
  • 38
  • 58
8
votes
3 answers

Does waitpid yield valid status information for a child process that has already exited?

If I fork a child process, and the child process exits before the parent calls waitpid, then is the exit status information that is set by waitpid still valid? If so, when does it become not valid; i.e., how do I ensure that I can call waitpid on…
Daniel Trebbien
  • 38,421
  • 18
  • 121
  • 193
8
votes
2 answers

Print in order of termination?

I've got a program which generates a random number, n, then loops n times. On each iteration, it randomizes the value of sleeptime, and calls fork. The child process sleeps for sleeptime seconds, then exits with the value of the index variable. The…
Moshe
  • 57,511
  • 78
  • 272
  • 425
7
votes
2 answers

What does reaping children imply?

I have just had a lecture that sums reaping as: Reaping Performed by parent on terminated child (using wait or waitpid) Parent is given exit status informaton Kernel then deletes zombie child process So I understand that reaping is done by calling…
That Guy
  • 2,349
  • 2
  • 12
  • 18
7
votes
2 answers

why did wait4() get replaced by waitpid()

I was going through the documentation of the system call wait4() and in its man page it is written These functions are obsolete; use waitpid(2) or waitid(2) in new programs. So, I went through the documentation of waitpid() and I saw that there is…
Haris
  • 12,120
  • 6
  • 43
  • 70
6
votes
3 answers

How to get the full returned value of a child process?

I need to catch the returned value of a child process.. The problem is: with using the waitpid() function I can catch only 8 bits of the returned value WEXITSTATUS(wstatus) returns the exit status of the child. This consists of…
Ebram Shehata
  • 446
  • 5
  • 20
1
2 3
19 20