[Haskell-cafe] how to terminate a (Posix) process and all its subprocesses?
Viktor Dukhovni
ietf-dane at dukhovni.org
Tue Jul 24 15:31:35 UTC 2018
> On Jul 24, 2018, at 9:42 AM, Johannes Waldmann <johannes.waldmann at htwk-leipzig.de> wrote:
>
> 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 ?)
You could start a wrapper process that starts the real process,
the wrapper process would kill the process group it spawned.
wrapper command [args ...]
would run command as a child in its own process group and propagates
termination signals (SIGHUP, SIGINT, SIGTERM) to the child process.
There are likely multiple such wrappers available. I don't have
a particular one to recommend.
--
Viktor.
More information about the Haskell-Cafe
mailing list