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

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!usc!news.cerf.net!netlabs!lwall
  3. From: lwall@netlabs.com (Larry Wall)
  4. Subject: Re: system() vs exec()
  5. Message-ID: <1992Dec16.191424.21911@netlabs.com>
  6. Sender: news@netlabs.com
  7. Nntp-Posting-Host: scalpel.netlabs.com
  8. Organization: NetLabs, Inc.
  9. References: <mcook.724446650@fendahl.dev.cdx.mot.com>
  10. Date: Wed, 16 Dec 1992 19:14:24 GMT
  11. Lines: 48
  12.  
  13. In article <mcook.724446650@fendahl.dev.cdx.mot.com> mcook@fendahl.dev.cdx.mot.com (Michael Cook) writes:
  14. : The manpage says this:
  15. :           system LIST
  16. :                   Does exactly the same thing as "exec LIST" except that a
  17. :                   fork is done first, and the parent process waits for the
  18. :                   child process to complete.
  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()
  21. : ignores SIGINT and SIGQUIT while it is waiting for the child to finish.
  22.  
  23. Okay, how 'bout I make it say, "...waits for the child process to complete
  24. or get blown out of the water."  :-)
  25.  
  26. : This means that a Perl script that use system() can be difficult to interrupt.
  27. : For example:
  28. :   foreach (@files)
  29. :   {
  30. :     system("cp $_ $dest/$_");
  31. :     $exit = $? if $?;
  32. :   }
  33. :   exit($exit);
  34. : If you try to ^C this script, it will simply start a new iteration of the
  35. : foreach loop (most likely).
  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. : At best, this is a bug in the manpage.  At worst, it is a bug in perl.
  39.  
  40. Well, it's the way most implementations of C's system() call work.
  41. It's not generally documented in the system(3) manpage either.  But
  42. I agree that it's a bit unexpected at times.  On the other hand, if
  43. it were the other way you'd also get surprised at times.  It could
  44. certainly be better documented.
  45.  
  46. : Hey, Larry: Will Perl 5.0 be able to do my taxes for me? :-)
  47.  
  48. Yes, Perl 5.0 could do your taxes for you, but then, so could nroff.
  49.  
  50. Larry
  51.  
  52. P.S. 98.63%.  Unfortunately, to get it up to 99.44% I'd have add a
  53. bunch more tests, since I'm now failing only one (1) test.  The apparatus
  54. for lexical scoping is mostly in place, and recursion now works again.
  55.