programming-examples/perl/CGI/Distinguish between the parent and child processes.pl

14 lines
323 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
# If fork returns 0, the current process is the child and not the parent.
# If an error occurs, fork returns a special undefined value called undef.
$pid = fork();
if ($pid == 0) {
# We're in the child process.
} elsif (! defined $pid) {
# Not defined: means an error.
} else {
# Parent process.
}