home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5302 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.9 KB

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