[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

how to kill a subprocess nicely?



Hi there,

I have a question that may not be directly correlated to GTK, but
perhaps some of you has an idea...

In my GTK-App I start a subprocess via fork and
execl("/bin/sh", "sh", "-c", cmd ,NULL)

Then I set a gdk_input_add on this to get the output of the subprocess...
all is working very nicely. Just one problem. 
I have an "Abort" button in my GUI which should cause that the subprocess
terminates. 

I tried to send an SIGINT via kill-command to the pid I get back from
the fork (which is the /bin/sh...). But the Shell does not pass this
signal to its child (my subprocess). 
According to kill(2) manpage sending the signal to an negative pid should
also kill all in the same process-group. I tried that too..but the child
runs happily along. If I patch my subprocess to output at startup its
own pid and I pick this output up and send my SIGINT to this pid everything
works as expected. 

But I cant patch all programs I want to call...
Another possiblty seems not to spawn my subprocesses via /bin/sh -c, but
this seems the way it is usually done....(and its nice too, because then
I can use &2>1 stuff ...)

Anybody with an idea who to kill that process? 
(with no parsing of ps-output or /proc)

Thanx,

Thomas

  ___ ___               
 /   |   \  ___________   | REAL   : Thomas Niederreiter: Munich, Germany  
/    ~    \/  _ \_  __ \  | EMAIL  : tn@mailserv.rz.fh-muenchen.de 
\    Y    (  <_> )  | \/  | IRC    : _Hor  
 \___|_  / \____/|__|     | 
       \/ All I want is a warm bed and a kind word and unlimited power         
                      -- Ashleigh Brilliant



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]