use strict; use warnings; use constant FORK_WAIT => 2; use constant MAX_ATTEMPTS => 10; our $attempt = 0; my $pid = undef; while (not defined ($pid = fork())) { die "Too many failed fork() attempts: $!\n"      if ++$attempt > MAX_ATTEMPTS;   warn "fork() failed: $!\n";   sleep FORK_WAIT; } if ($pid) { # I'm the father } else { # I'm the son }