home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!network.ucsd.edu!news!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Newsgroups: comp.lang.perl
- Subject: Re: help with timeouts
- Keywords: rsh, fork
- Message-ID: <1992Aug13.201026.16042@netlabs.com>
- Date: 13 Aug 92 20:10:26 GMT
- Article-I.D.: netlabs.1992Aug13.201026.16042
- References: <1992Aug7.145613.24831@lamont.ldgo.columbia.edu>
- Sender: news@netlabs.com
- Organization: NetLabs, Inc.
- Lines: 28
- Nntp-Posting-Host: scalpel.netlabs.com
-
- In article <1992Aug7.145613.24831@lamont.ldgo.columbia.edu> msolda@lamont.ldgo.columbia.edu writes:
- : a script in perl that i am writing would fork and then exec a process which
- : creates output to a logfile. i would like to timeout the exec'ed process.
- : this would require an alarm to go off after a set amount of time and then
- : if the logfile has not been modified since the exec'ed process began, kill
- : the exec'ed process. otherwise continue normally, as if the signal didn't
- : go off.
- :
- : i see how to implement a signal handler routines that abort an exec'ed
- : process and then die, but i don't see a good way to implement a handler
- : that can either kill the exec'ed process and die or just conitnue on if
- : the correct conditions are met.
-
- You could just do it in a signal handler, and if you decide not to kill
- the process, just return. This has one potential problem in that some
- system calls might fail with errno == EINTR, and have to be restarted.
- This can be messy if you're dealing with some random stdio package...
-
- A cleaner way would be to spawn off a third process that just sleeps
- for a while, then looks to see if it should kill the other process, and
- if not, just exits. No muss, no fuss.
-
- A third way, if you have control of the logging process, is to have it
- set its own alarm, which will blow it away by default when it goes
- off. Then if it decides to produce any output, it first says alarm(0)
- to turn the pending alarm off.
-
- Larry
-