home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / languages / perl / nutshell / ch4 / fork < prev    next >
Encoding:
Text File  |  1992-10-18  |  382 b   |  17 lines

  1. FORK: {
  2.     if ($pid = fork) {
  3.         # parent here
  4.         # child process pid is available in $pid
  5.     } elsif (defined $pid) { # $pid is zero here if defined
  6.         # child here
  7.         # parent process pid is available with getppid
  8.     } elsif ($! =~ /No more process/) {     
  9.         # EAGAIN, supposedly recoverable fork error
  10.         sleep 5;
  11.         redo FORK;
  12.     } else {
  13.         # weird fork error
  14.         die "Can't fork: $!\n";
  15.     }
  16. }
  17.