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
6
votes
3 answers

kill & wait in one step

If I use a combination to kill a child process in batch and wait for it's termination, I use kill $PID wait $PID If the process exists immediately, the wait will fail, since the pid is not running anymore. Is there a way to combine both statements…
urzeit
  • 2,863
  • 20
  • 36
6
votes
2 answers

Why is Perl's $? returning the wrong value for the exit code of a forked process?

Consider this trivial example of fork()ing then waiting for a child to die in Perl: #!/usr/bin/perl use strict; use warnings; if (fork() == 0) { exit(1); } waitpid(-1,0); print $?; Running the script on Solaris 10 I get this result: $…
Mike
  • 58,961
  • 76
  • 175
  • 221
6
votes
3 answers

Why does Linux program that derefrences (char*)0 not always segfault?

I'm testing code that is designed to detect when a child process has segfaulted. Imagine my surprised when this code does not always segfault: #include int main() { char *p = (char *)(unsigned long)0; putchar(*p); return 0; } I'm…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
6
votes
2 answers

Linux, waitpid, WNOHANG and zombies

I need to be able to: fork a process and make it execvp (I did that) check if the child process execvp was successful (don't know how) check if the child process finished (having problems) I'm forking a process and I don't have any way to check if…
m1o2
  • 1,549
  • 2
  • 17
  • 27
5
votes
4 answers

Test cases in C for WIFSIGNALED, WIFSTOPPED, WIFCONTINUED

I'm playing with waitpid() and signal() and I'm looking for reliable test cases for returning WIFSIGNALED(status) = WIFSTOPPED(status) = WIFCONTINUED (status) = true but can't find any... Care to tell me how can I make sure those return true so I…
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
5
votes
1 answer

Perl timeout command in windows and linux

I'm writing a perl script that needs to work in windows and linux that will run a process, timeout if it takes too long, return the exit code assuming it didn't timeout, and return stdout assuming the exitcode was zero and it didn't timeout. I don't…
serpixo
  • 310
  • 1
  • 7
5
votes
4 answers

execv and fork: inform parent that child failed to execute the file

How can the master process know that the child process failed to execute the file (e.g. no such file or directory)? For example, in the following code, how can we get run() to return something other than 0? Thanks! #include #include…
psilouette
  • 83
  • 1
  • 6
5
votes
3 answers

Linux, waitpid, WNOHANG, child process, zombie

I running my program as daemon. Father process only wait for child process, when it is dead unexpected, fork and wait again. for (; 1;) { if (fork() == 0) break; int sig = 0; for (; 1; usleep(10000)) { pid_t wpid = waitpid(g->pid[1], &sig,…
Cube
  • 181
  • 2
  • 9
5
votes
2 answers

Can this C code create zombie processes?

I am wondering if the following code can create zombies: #include #include #include #include int main(){ int i=1; pid_t p; p = fork(); i++; if(p!=0){ waitpid(p, NULL, 0); …
mgus
  • 808
  • 4
  • 17
  • 39
5
votes
2 answers

How to make waitpid block the loop

The following code runs 2 children, who will wait for 10 seconds and terminate. The parent is sitting in a loop, waiting for the children to terminate: #!/usr/bin/perl use strict; use warnings; use POSIX ":sys_wait_h"; sub func # {{{ { my $i…
user4035
  • 22,508
  • 11
  • 59
  • 94
5
votes
1 answer

fork/exec/waitpid issue

I'm trying to determine whether an execution failed by checking the result of waitpid(). However, even when I run a command that I know fails and writes the issue to stderr, the check below never registers. What could possibly be wrong with this…
Jim Ruffian
  • 53
  • 1
  • 4
5
votes
1 answer

Multiple pipe implementation using system call fork() execvp() wait() pipe() - it is simply not working

I need to implement my shell that handles multiple pipe commands. For example I need to be able to handle this: ls | grep -i cs340 | sort | uniq | cut -c 5. I am assuming the problem is that I am not passing output of the previous command to the…
user1090944
  • 445
  • 1
  • 8
  • 16
4
votes
3 answers

How to timeout waitpid without killing the child?

I am aware of the many questions regarding waitpid and timeouts but they all cover this by killing the child from within an alarm handler. That is not what i want, i want to keep the process running but dispatch it from waitpid. The underlaying…
matthias krull
  • 4,389
  • 3
  • 34
  • 54
4
votes
1 answer

Oracle beq and popen()

I have a program like this (that's for Pro*C precompiler): #include #include #include #include EXEC SQL BEGIN DECLARE SECTION; static VARCHAR ora_connect_str[81]; EXEC SQL END DECLARE SECTION; EXEC SQL…
user332325
4
votes
1 answer

Race condition in my POSIX signal handler

The following program forks off a child, that runs "/bin/sleep 10" repeatedly. The parent installs a signal handler for SIGINT, that delivers SIGINT to the child. However sometimes sending SIGINT to the child fails. Why is that and what do I…
kmkkmk
  • 43
  • 3
1
2
3
19 20