I need to handle SIGCHLD
properly. How can I use it with my existing code? at the moment I cant wait for the child process unless I use 0
instead of WNOHANG|WUNTRACED
.
status = 0;
pid_t child, endID;
if(amp == 1)
signal( SIGCHLD, SIG_IGN );
child = fork();
if (child < 0) {
perror("fork() error\n");
exit(EXIT_FAILURE);
} else if (child == 0) {
// do sth here
perror("error\n");
} else {
//sleep(1)
If I remove sleep
then parent is executed 1st.. why?
Here is a start (but read below):
Of course, this is all pointless. If the parent simply ignores
SIGCHLD
, the children are silently reaped and won't turn into zombies.Quoting TLPI:
So something like this should do the trick for you: