Date: Tue, 18 Feb 2003 08:40:00 +0000 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: freebsd-questions@FreeBSD.ORG Subject: Re: SIGCHLD Message-ID: <20030218084000.GA16438@happy-idiot-talk.infracaninophi> In-Reply-To: <20030210193525.D78057-100000@amour.ath.cx> References: <20030210193525.D78057-100000@amour.ath.cx>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Feb 10, 2003 at 07:52:06PM +0100, Alexander wrote: > I'm having a problem when running a program that forks a child. > The program handles SIGCHLD with its own function that calls waitpid(). > So the program thinks that when SIGCHLD is raised then the child is terminated. > But the parent gets SIGCHLD even if the child is still running and then > the following happens - The child is doing its job but the parent > calls the SIGCHLD handler and gets into waitpid() (although it shouldn't !) > > SIGNAL(3) manual page says: > Name Default Action Description > > SIGCHLD discard signal child status has changed > > Does this mean that SIGCHLD is not only raised when the process is terminated ? Yes. Look at the wait(2) man page: the parent process can receive a SIGCHLD when the child process is stopped, by eg. a SIGSTOP signal. However, you only get that if you set the WUNTRACED option in the waitpid() call. It's also possible for your parent process to receive SIGCHLD signals for any descendant process in the same process group, depending on the value of the wpid parameter. Unless you've called setsid(2) or used the double fork(2) trick, your child process, and any grandchild process it spawns will all belong to the same process group as your original program. It's exceedingly unlikely that such a fundamental part of process control could be buggy without leaving an enormous trail all over the mailing lists. However, it was the case that perl(1) used to have problems with SIGCHLD propagation on FreeBSD: http://archive.develooper.com/perl5-porters@perl.org/msg89611.html > And does it mean, "always ignore SIGCHLD and never trust it" ? The sigaction(2) man page explains how you control the behaviour of a program in response to signals. > And what does this mean "child status has changed" ? When is it changed ? Uh --- the signal should be delivered pretty much instantaneously with the child process changing status. 'Changing status' means that the child process has called exit(3) or _exit(2) or received a signal such as SIGINT or SIGKILL which will cause the child process to exit. It can also mean that the child received a SIGSTOP or SIGTSTP or SIGCONT or similar which has caused it to temporarily stop or restart execution. Cheers, Matthew -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way PGP: http://www.infracaninophile.co.uk/pgpkey Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030218084000.GA16438>