[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: how to kill a subprocess nicely?
- From: rsmith xs4all nl
- To: gtk-app-devel-list redhat com
- Subject: Re: how to kill a subprocess nicely?
- Date: Sun, 8 Aug 1999 11:48:17 +0200 (CEST)
On 2 Aug, Thomas Niederreiter wrote:
> 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.
You could exec your app directly, using two pipe(2)s that you can link
to the child's standard input/output via fcntl(2) or dup2(2).
That way you can have two-way communication with the exec-ed process
and you can kill it easily. Or you could send a stop command to the
process via the pipe.
If you want an example, take a look at the plug-in code of the Giram 3D
modeller. I would think that the Gimp does something similar, but I
don't know where to find it in the source.
Roland
--
Roland Smith "Time is what prevents everything
r s m i t h @ x s 4 a l l . n l from happening at once"
http://www.xs4all.nl/~rsmith/
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]