home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!krfiny!jeffj
- From: jeffj@krfiny.uucp (J. Jonas)
- Subject: Re: Queueing of signals
- Message-ID: <1992Aug14.173144.20835@krfiny.uucp>
- Keywords: SIGCHLD, signals, queueing, sigvec
- Organization: Jeff's house of computer pieces
- References: <1992Aug13.160824.11077@bwdls61.bnr.ca>
- Date: Fri, 14 Aug 1992 17:31:44 GMT
- Lines: 69
-
- In article <1992Aug13.160824.11077@bwdls61.bnr.ca> gwaters@bwdls139.bnr.ca
- (Glenn Waters) writes:
- >I have a program that seems to lose SIGCHLD signals. There are two (or more)
- >processes that die simultaneously -- thus generating two SIGCHLDs
- >to the parent. I only seem to get the first SIGCHLD.
- >
- >Are the signals queued? I believe not.
-
- The "traditional' Unix signal handler has a variable with
- ONE BIT for each signal to indicate that the signal has occurred.
- Using signal(2), there's a pointer to a function for each signal
- with either ignores it, does a default action, or calls a function that
- you specified in the signal(2) call.
- Setting the bit causes the corresponding action to take place.
- Upon entry to the signal handler, the input bit was reset and
- the action could revert to the default.
- (That's why signal handlers with signal(2) usually re-catch the
- signal as the first action, and then handle re-entrancy).
-
- Using sigset(2), there's a "MASK" between the variable of incoming
- signals and the signal handler, thus you can hold and release
- signal handling.
-
- Still, there's only ONE BIT to show that the signal has occurred.
- So, yes, you're correct. Signals are not queued nor counted.
- Semaphores or messages are for that.
-
- >What is the correct method of catching the subsequent child deaths that are
- >not queued?
-
- I have a program that spawns 2 processes and then continues to perform
- some background processing.
- There are times that both children terminate and only one SIGCHILD is
- received. Since any termination causes all to exit, I don't care if
- there's an unwaited for child when the process exits.
-
- I'm composing this as I post, so play around with this idea:
- assume the child signal catcher in being called for possibly
- more than 1 child. Since wait(2) has no NO_DELAY option,
- put an alarm around it to time it out when there are no
- other terminated children.
- If you have a timer that allows sleeps of less than 1 second,
- that's even better!
-
-
- sigset (SIGCLD, catchSigChild);
-
-
- void catchSigChild (int sig)
- {
- pid_t ret;
- int status;
-
- alarm (1);
- while ((ret = wait (&status)) != (-1))
- {
- alarm (1); /* reset alarm */
- printf("child pid %d terminated with status %d\n", ret, status);
- }
- /* return when wait() returns -1 with ECHILD or EINTR */
- }
-
- - Jeffrey Jonas
- jeffj@synsys.uucp
- --
- --
- Jeffrey Jonas
-
- jeffj@synsys.uucp
-