home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7444 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.4 KB  |  45 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!fendahl.dev.cdx.mot.com!mcook
  3. From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
  4. Subject: system() vs exec()
  5. Message-ID: <mcook.724446650@fendahl.dev.cdx.mot.com>
  6. Sender: news@merlin.dev.cdx.mot.com (USENET News System)
  7. Nntp-Posting-Host: fendahl.dev.cdx.mot.com
  8. Organization: Motorola Codex, Canton, Massachusetts
  9. Date: Tue, 15 Dec 1992 19:10:50 GMT
  10. Lines: 33
  11.  
  12. The manpage says this:
  13.  
  14.           system LIST
  15.                   Does exactly the same thing as "exec LIST" except that a
  16.                   fork is done first, and the parent process waits for the
  17.                   child process to complete.
  18.  
  19. This is not completely accurate.  There is an important difference between
  20. system() and exec() that the manpage doesn't seem to mention: system() ignores
  21. SIGINT and SIGQUIT while it is waiting for the child to finish.
  22.  
  23. This means that a Perl script that use system() can be difficult to interrupt.
  24. For example:
  25.  
  26.   foreach (@files)
  27.   {
  28.     system("cp $_ $dest/$_");
  29.     $exit = $? if $?;
  30.   }
  31.   exit($exit);
  32.  
  33. If you try to ^C this script, it will simply start a new iteration of the
  34. foreach loop (most likely).
  35.  
  36. If you write the script using fork, exec and waitpid, when you hit ^C it does
  37. what you'd expect: it dies.
  38.  
  39. At best, this is a bug in the manpage.  At worst, it is a bug in perl.
  40.  
  41. Michael.
  42.  
  43. P.S. 
  44. Hey, Larry: Will Perl 5.0 be able to do my taxes for me? :-)
  45.