wait
wait
- Waits for a child process to terminate and returns the pid of the deceased process, or
-1
if there are no child processes. The status is returned in$?
. If you get zombie child processes, you should be calling either this function orwaitpid
. A common strategy to avoid such zombies is:
$SIG{CHLD} = sub { wait };
If you expected a child and didn't find it, you probably had a call tosystem
, a close on a pipe, or backticks between thefork
and thewait
. These constructs also do await(2)
and may have harvested your child process. Usewaitpid
to avoid this problem.