home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!usc!news.cerf.net!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Subject: Re: system() vs exec()
- Message-ID: <1992Dec16.191424.21911@netlabs.com>
- Sender: news@netlabs.com
- Nntp-Posting-Host: scalpel.netlabs.com
- Organization: NetLabs, Inc.
- References: <mcook.724446650@fendahl.dev.cdx.mot.com>
- Date: Wed, 16 Dec 1992 19:14:24 GMT
- Lines: 48
-
- In article <mcook.724446650@fendahl.dev.cdx.mot.com> mcook@fendahl.dev.cdx.mot.com (Michael Cook) writes:
- : The manpage says this:
- :
- : system LIST
- : Does exactly the same thing as "exec LIST" except that a
- : fork is done first, and the parent process waits for the
- : child process to complete.
- :
- : This is not completely accurate. There is an important difference between
- : system() and exec() that the manpage doesn't seem to mention: system()
- : ignores SIGINT and SIGQUIT while it is waiting for the child to finish.
-
- Okay, how 'bout I make it say, "...waits for the child process to complete
- or get blown out of the water." :-)
-
- : This means that a Perl script that use system() can be difficult to interrupt.
- : For example:
- :
- : foreach (@files)
- : {
- : system("cp $_ $dest/$_");
- : $exit = $? if $?;
- : }
- : exit($exit);
- :
- : If you try to ^C this script, it will simply start a new iteration of the
- : foreach loop (most likely).
- :
- : If you write the script using fork, exec and waitpid, when you hit ^C it does
- : what you'd expect: it dies.
- :
- : At best, this is a bug in the manpage. At worst, it is a bug in perl.
-
- Well, it's the way most implementations of C's system() call work.
- It's not generally documented in the system(3) manpage either. But
- I agree that it's a bit unexpected at times. On the other hand, if
- it were the other way you'd also get surprised at times. It could
- certainly be better documented.
-
- : Hey, Larry: Will Perl 5.0 be able to do my taxes for me? :-)
-
- Yes, Perl 5.0 could do your taxes for you, but then, so could nroff.
-
- Larry
-
- P.S. 98.63%. Unfortunately, to get it up to 99.44% I'd have add a
- bunch more tests, since I'm now failing only one (1) test. The apparatus
- for lexical scoping is mostly in place, and recursion now works again.
-