Question about terminateProcess

Hi, http://hackage.haskell.org/package/process-1.2.0.0/docs/System-Process.html#... says: " Note: on Windows, if the process was a shell command created by createProcess with shell, or created by runCommand or runInteractiveCommand, then terminateProcess will only terminate the shell, not the command itself. On Unix systems, both processes are in a process group and will be terminated together. " I don't see that happening, at least not in ghci. When I do import System.Process (_,_,_,p) <- createProcess $ (shell "sleep 10") -- wait a second or so terminateProcess p in ghci, then in `ps aux | grep "sleep 10"`, the sleep is still running; same when I'm using `(shell "sleep 10"){ create_group = True }` (`shell` defaults to `create_group = False`). What am I missing?

On Fri, Jun 19, 2015 at 10:00 PM, Niklas Hambüchen
Note: on Windows, if the process was a shell command created by createProcess with shell, or created by runCommand or runInteractiveCommand, then terminateProcess will only terminate the shell, not the command itself. On Unix systems, both processes are in a process group and will be terminated together.
Last I checked, that was just wrong on Unix; it kills only the shell. This is probably because someone did not consider that most modern shells support job control, and therefore start commands in their own independent process groups. (Or assumed that this does not happen with "sh -c"; I would have to test specific shells --- and versions! various bash versions can behave quite differently and often have bugs lurking in the dark corners --- to see if this applies.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On Fri, Jun 19, 2015 at 10:17 PM, Brandon Allbery
I would have to test specific shells --- and versions! various bash versions can behave quite differently and often have bugs lurking in the dark corners --- to see if this applies.
FWIW dash as shipped on Mint 17 and bash 4.3.11(1) do not create a new pgrp with sh -c, at least by default. I think you can turn job control on even in noninteractive bash if you try hard enough, though. bash -c 'echo shell=$$; perl -le "print qq{perl=\$\$}; print qq{pgrp=}, getpgrp(0)"' Replace "bash" with "sh" or other specific shell you want to test; if the "pgrp" is the same as the "perl" then the shell is doing job control, if it's the same as "shell" then it is not and (at least in theory) create_group + terminateProcess should work. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (2)
-
Brandon Allbery
-
Niklas Hambüchen