programming-examples/perl/SystemFunction/Waiting for child processes to exit.pl
2019-11-15 12:59:38 +01:00

23 lines
397 B
Perl

#!/usr/bin/perl -w
$pid = fork();
if ($pid == 0) {
print "We're in the child process.";
exit(0); # Terminate child.
} elsif (! defined $pid) {
print "Not defined: means an error.";
} else {
print "Parent process.";
print "Do something...";
# Reap child.
$id = wait();
# Do something after child dies.
print "Child $id is dead.\n";
}