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

Levent Erkok erkokl at gmail.com
Tue Jul 24 17:51:52 UTC 2018

Hi Johannes:

I had a similar question a few years back using the async library and in
particular the 'race' function. I got a nice answer on StackOverflow:


I think you can use the ideas in there. Bottom line: You can use a
combination of 'onException' and 'terminateProcess' and let your spawned
processes clean-up after themselves properly.



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

> Dear Cafe,
> I am using
> https://hackage.haskell.org/package/process-
> 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-
> 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-
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180724/1d7d675b/attachment.html>

More information about the Haskell-Cafe mailing list