Ctrl-Z
(suspend) in the midst of
execution and then enter a ps
command. Zombies
appear as <defunct> processes.
Either of wait
or waitpid
can be used to remove zombies.
wait
(and waitpid
in it's blocking form) temporarily
suspends the execution of a parent process while a child process is running. Once the
child has finished, the waiting parent is restarted.
Declarations:
#include <sys/types.h> #include <sys/wait.h> pid_t wait(int *statloc); /* returns process ID if OK, or -1 on error */ pid_t waitpid(pid_t pid, int *statloc, int options); /* returns process ID : if OK, * 0 : if non-blocking option && no zombies around * -1 : on error */
The statloc
argument can be one of two values:
wait() | waitpid() |
wait blocks the caller until a child process terminates |
waitpid can be either blocking or non-blocking:
|
if more than one child is running then wait() returns the first time one of the parent's offspring exits |
waitpid is more flexible:
|
References