[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KProcess eats SIGCHLD, so pclose() fails
From:       Luis Pedro Coelho <luis_pedro () netcabo ! pt>
Date:       2001-11-29 20:01:25
[Download RAW message or body]

Em Quarta, 28 de Novembro de 2001 21:18, David Faure escreveu:
> On Wednesday 28 November 2001 20:28, aleXXX wrote:
> > On Wed 28 Nov 01 18:32, David Faure wrote:
> > > KProcessController, instantiated by KProcess, seems to grab all SIGCHLD
> > > events, even the ones that have nothing to do with KProcess.
> > 
> > After looking at the code, it grabs exactly SIGCHLD and SIGPIPE since it
> > has to know when its child dies.
>
> Yes, but maybe there's a way to tell it to ignore a certain pid, or to
> forward unknown signals, or...

I think this is impossible to do correctly. I beleive that a desirable 
behaviour would be for the KProcess signal handler to remember if any 
handlers were installed before it and then to foward unwanted received 
signals to this handler.

So I thought of (pseudo-code):

int status;
bool handled = false;
foreach process in processesWeMonitor {
	if (waitpid(process.pid,&status,WNOHANG) > 0) {
		handled = true;
		fancyStuff(process.pid,status);
	}
}
if (!handled) oldHandler(SIGCHLD);


I however think that this code has one flaw: if I have two child processes A 
and B. Lets assume A is in the processesWeMonitor list, while B is not. Lets 
also assume that they end at the same time (which means that they end in the 
time where our process is away from the processor). Then we, the parent 
process, will receive one SIGCHLD referring to both processes. Then the 
method above will fail, since handled will be set to true after we waited for 
A. Noone will ever wait() on B.

Another alternative would be to always call the handler but that is even 
worse: If oldHandler expects to always be able to wait on someone, it will 
hang the process (until some child dies).

HTH,
-- 
Luis Pedro Coelho.

Check out my game of Hearts, a card game, for KDE at:
http://hearts.sourceforge.net/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic