waitpid

waitpidPID,FLAGS
This function waits for a particular child process to terminate
and returns the PID when the process is dead, –1 if there are no child processes, or
0 if the
FLAGS specify nonblocking and the process
isn’t quite dead yet. The status of any dead process is returned in
$?, as described under system. To get valid flag values, you’ll need
to import the “:sys_wait_h” import
tag group from the POSIX module. Here’s an example that does a nonblocking wait
for all pending zombie processes.
use POSIX ":sys_wait_h";
do {
$kid = waitpid(–1,&WNOHANG);
} until $kid == –1;On systems that implement neither the
waitpid(2) nor wait4(2)
syscall, FLAGS may be specified only as
0. In other words, you can wait for a
specific PID there, but you can’t do so in
nonblocking mode.
On some systems, a return value of –1 could mean that child processes are being
automatically reaped because you set $SIG{CHLD}
= "IGNORE".
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access