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 / ch5 / forkdaemon < prev    next >
Encoding:
Text File  |  1992-10-18  |  296 b   |  16 lines

  1. unless (fork) { # this is the child
  2.     unless (fork) { # this is the child's child
  3.     sleep 1 until getppid == 1;
  4.     _L_O_N_G_O_P_E_R_A_T_I_O_N;
  5.     exit 0;
  6.     }
  7.     # first child exits quickly
  8.     exit 0;
  9. }
  10. wait; # parent reaps first child quickly
  11.  
  12. # or...
  13.  
  14. fork && exit;
  15. setpgrp(0,$$);
  16.