home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ftpbox!mothost!merlin.dev.cdx.mot.com!fendahl.dev.cdx.mot.com!mcook
- From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
- Subject: system() vs exec()
- Message-ID: <mcook.724446650@fendahl.dev.cdx.mot.com>
- Sender: news@merlin.dev.cdx.mot.com (USENET News System)
- Nntp-Posting-Host: fendahl.dev.cdx.mot.com
- Organization: Motorola Codex, Canton, Massachusetts
- Date: Tue, 15 Dec 1992 19:10:50 GMT
- Lines: 33
-
- 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.
-
- 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.
-
- Michael.
-
- P.S.
- Hey, Larry: Will Perl 5.0 be able to do my taxes for me? :-)
-