the OP only wants two processes in parallel which is too obviously not a case where undef can occur.
$ cat cantfork.pl
#!/usr/bin/perl
use strict;
use warnings;
my $child = fork;
die "Well that's odd - the fork failed" unless defined $child;
if ($child) {
print "Parent! Child is $child\n";
} else {
print "Child!\n";
}
sleep 1;
exit;
$ ./cantfork.pl
Parent! Child is 17198
Child!
$ ulimit -u 9
$ ./cantfork.pl
Well that's odd - the fork failed at ./cantfork.pl line 6.
Always code defensively, especially when using system calls as they can fail at any time for any reason. |