home *** CD-ROM | disk | FTP | other *** search
- 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
- From: smr@pki-nbg.philips.de (Stephen Riehm)
- Newsgroups: comp.lang.c
- Subject: Re: Wait for child
- Message-ID: <smr.721989049@hitkw14>
- Date: 17 Nov 92 08:30:49 GMT
- References: <1992Nov16.122725.15971@alf.uib.no>
- Sender: news@pki-nbg.philips.de
- Reply-To: smr@pki-nbg.philips.de
- Lines: 55
-
- singg@alf.uib.no (Kurt George Gjerde) writes:
-
- >On Unix, how can I have a process wait for it's child process to do something
- >(not terminate).
-
- >I've tried using sigpause (couldn't find pause) in the parent process, and
- >having the child to send SIGCONT, but that didn't work...
-
- >Any ideas?
-
- Using signals:
- set up a signal handler for SIGUSR1 or SIGUSR2, using either
- signal(2), sigset(2), or sigpause(2).
- use wait(2) to sleep until a signal is received ( unless you
- are using sigpause(2) )
-
- The signal handler will only be called if a SIGUSR1 or SIGUSR2
- is sent (from the child), any other signal will only terminate the
- wait call, so you can put some error trapping after the wait,
- eg: if your signal handler was called then the code can go ahead
- as normal, otherwise, erase some disks, core dump,
- send abusive mail to random users, and finally crash the
- system.
-
- >( Right now it works with the parent constantly checking the existence of a
- > file. When the child removes the temp-file, the parent continues...
- > THIS SLOWS DOWN THE SYSTEM! )
-
- Using a status file of some sort:
- in SYSV (at least) there is select(2), this is a very
- economical way of waiting for input from a variety of sources.
- In short, all you need to do is give it a bunch of file
- descriptors (not file pointers), and some details about what
- to do, and it will sleep until there is some input waiting on
- one of those file descriptors, it then returns information
- about which file descriptors have data waiting to be read. You
- could set up a pipe, or a file, and the child could simply
- send single character status reports when something happens.
- (Make sure everything is properly flushed!)
- In this way the parent could monitor many children
- simultaneously, and the information flow between the processes
- is somewhat more flexible. (signals don't tell you anything
- about WHICH child, or what the child is doing, unless you use
- many different signals), the parent could even send replies.
-
- Hope this helps, this is all theoretical only, I have written some
- stuff using this style of communications before, but that was years
- ago ;-)
-
- -----------------------------------------------------------------
- Stephen Riehm Configuration Management _-_|\
- smr@pki-nbg.philips.de Philips Kommunikations Industrie / \
- Work: +49 911 526 2975 Nu"rnberg, Germany \_.-.!/
- Fax: +49 911 526 3678 "I was there, now I am here!" v
- "My company speaks another language, I CAN'T speak on its' behalf"
-