waitpid
Waits for a specific child process to change state.
Suspends the current process until the child identified by $pid
terminates (or changes state, depending on flags). Sets $? to
the wait status.
Returns:
- The PID of the terminated child on success
0ifWNOHANGwas specified and no child has exited yet-1on error (e.g. no such child)
When $pid is -1, waits for any child (equivalent to wait()).
Synopsis
my $result = waitpid($pid, 0); # blocking wait
my $result = waitpid($pid, WNOHANG); # non-blocking
my $result = waitpid(-1, 0); # any child (like wait)