Penguin
Note: You are viewing an old revision of this page. View the current version.

Signal: Child process

Child process has changed state. This signal is raised whenever a child process recieves a signal or terminates. This can be used to call wait4(2) to cleanup any ZombieProcesses that the process may have. On some Unix's it is possible to explicitly set SIGCHLD to "SIG_IGN" (ignore) and child processes will be cleaned up automatically. The default action (SIG_DFL) for this signal is to ignore it (but this does not reap the process until the parent wait()s).

In perl, would do one of the following:

1. wait till child finishes


if (fork()==0) {

  1. ==0 implies child process

do stuff... exit;

}

  1. if fork returned -1, there was an error forking (but we'll ignore that)
  2. if here, assume it is the parent processes

wait(); # when this returns, the child has been "reaped"

  1. when here, the child process has finished.

...


2. Don't care about the child process finishing


$SIG{CHLD}='IGNORE'; # see the perlipc(1) man page for this...

if (fork()==0) {

do child stuff... exit;

}

continue in parent....


If you don't do either of wait() or set the signal handler, then the child will remain a ZombieProcess.