[Haskell-cafe] how to terminate a (Posix) process and all its subprocesses?

Brandon Allbery allbery.b at gmail.com
Tue Jul 24 18:05:39 UTC 2018


The trick here is to set the option that creates a process group
(System.Process's config record has a field for this), then extract the
process id of the parent and negate it to get a process group ID. A signal
sent to that will go to the entire process group.

You can do this with System.Process as opposed to System.Posix.Process, but
you need to go digging into internals to get the process ID IIRC.

On Tue, Jul 24, 2018 at 9:42 AM Johannes Waldmann <
johannes.waldmann at htwk-leipzig.de> wrote:

> Dear Cafe,
>
> I am using
>
> https://hackage.haskell.org/package/process-1.6.4.0/docs/System-Process.html#v:readProcess
> to start an external command, and wait for its completion.
>
> Now I would like to time-out this after a while.
> I can use
> https://hackage.haskell.org/package/base-4.11.1.0/docs/System-Timeout.html
> and this works in simple cases -
>
> but not in case the external command has spawned child processes.
> (cleanupProcess sends SIGTERM but only to the process at the top of
> the tree ?)
>
> I guess I need to use
>
> https://hackage.haskell.org/package/unix-2.7.2.2/docs/System-Posix-Process.html
> but that seems rather low-level - and I don't see how I would
> get the ProcessID of the process started by  readProcess,
> so I'd also have to re-do that.
>
> Is there an abstraction/library that would help here?
>
> Thanks - J.W.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.



-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180724/4db92b39/attachment.html>


More information about the Haskell-Cafe mailing list