home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16653 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  2.9 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!pki-nbg!hitkw14!smr
  2. From: smr@pki-nbg.philips.de (Stephen Riehm)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Wait for child
  5. Message-ID: <smr.721989049@hitkw14>
  6. Date: 17 Nov 92 08:30:49 GMT
  7. References: <1992Nov16.122725.15971@alf.uib.no>
  8. Sender: news@pki-nbg.philips.de
  9. Reply-To: smr@pki-nbg.philips.de
  10. Lines: 55
  11.  
  12. singg@alf.uib.no (Kurt George Gjerde) writes:
  13.  
  14. >On Unix, how can I have a process wait for it's child process to do something
  15. >(not terminate).
  16.  
  17. >I've tried using sigpause (couldn't find pause) in the parent process, and 
  18. >having the child to send SIGCONT, but that didn't work...
  19.  
  20. >Any ideas?
  21.  
  22. Using signals:
  23.     set up a signal handler for SIGUSR1 or SIGUSR2, using either
  24.         signal(2), sigset(2), or sigpause(2).
  25.     use wait(2) to sleep until a signal is received ( unless you
  26.         are using sigpause(2) )
  27.  
  28.     The signal handler will only be called if a SIGUSR1 or SIGUSR2
  29.     is sent (from the child), any other signal will only terminate the
  30.     wait call, so you can put some error trapping after the wait,
  31.     eg: if your signal handler was called then the code can go ahead
  32.         as normal, otherwise, erase some disks, core dump,
  33.         send abusive mail to random users, and finally crash the
  34.         system.
  35.  
  36. >( Right now it works with the parent constantly checking the existence of a
  37. >  file. When the child removes the temp-file, the parent continues... 
  38. >  THIS SLOWS DOWN THE SYSTEM! )
  39.  
  40. Using a status file of some sort:
  41.     in SYSV (at least) there is select(2), this is a very
  42.     economical way of waiting for input from a variety of sources.
  43.     In short, all you need to do is give it a bunch of file
  44.     descriptors (not file pointers), and some details about what
  45.     to do, and it will sleep until there is some input waiting on
  46.     one of those file descriptors, it then returns information
  47.     about which file descriptors have data waiting to be read. You
  48.     could set up a pipe, or a file, and the child could simply
  49.     send single character status reports when something happens.
  50.     (Make sure everything is properly flushed!)
  51.     In this way the parent could monitor many children
  52.     simultaneously, and the information flow between the processes
  53.     is somewhat more flexible. (signals don't tell you anything
  54.     about WHICH child, or what the child is doing, unless you use
  55.     many different signals), the parent could even send replies.
  56.  
  57. Hope this helps, this is all theoretical only, I have written some
  58. stuff using this style of communications before, but that was years
  59. ago ;-)
  60.  
  61. -----------------------------------------------------------------
  62. Stephen Riehm        Configuration Management       _-_|\ 
  63. smr@pki-nbg.philips.de    Philips Kommunikations Industrie  /     \
  64. Work: +49 911 526 2975    Nu"rnberg, Germany          \_.-.!/
  65. Fax:  +49 911 526 3678    "I was there, now I am here!"           v 
  66. "My company speaks another language, I CAN'T speak on its' behalf"
  67.