Code Snippets

#!/usr/bin/perl
use strict;
use warnings;

my $pid = fork();
die "fork failed: $!" unless defined $pid;

if ($pid == 0) {
    print "Child PID $$\n";
    sleep 1;
    exit 0;
} else {
    print "Parent waiting on $pid\n";
    waitpid($pid, 0);
    print "Child exited with $?\n";
}