[Haskell-cafe] How to terminate the process group of a processcreated with createProcess?

André Scholz andre.scholz at uni-bremen.de
Thu Jan 12 12:56:05 CET 2012

On 11.01.2012 at 23:08 Donn Cave wrote:
> Quoth Brandon Allbery <allbery.b at gmail.com>,
> ...
> > terminateProcess passes on the semantics of kill(2); on SVID-compliant
> > (and I think POSIX.1-compliant) systems, the negative of the process
> > group leader's process ID is used to signal the process group.  Note
> > that you may need to arrange for your initial child process to invoke
> > setpgrp() to insure that the parent program is not part of the process
> > group.
> ... and that stuff can be found in System.Posix.Process.  Support for
> POSIX killpg can be found in System.Posix.Signals, by the way in case
> you think that would make your intention more transparent.

I tried:

import System.Posix.Process
import System.Posix.Signals
import System.Process
import System.Process.Internals

terminateProcessGroup :: ProcessHandle -> IO ()
terminateProcessGroup ph = do
    let (ProcessHandle pmvar) = ph
    ph_ <- readMVar pmvar
    case ph_ of
        OpenHandle pid -> do  -- pid is a POSIX pid
            gid <- createProcessGroup pid
            signalProcessGroup 15 pid
        otherwise -> error "Somethings wrong."

but i get the error message:
"createProcessGroup: permission denied"

Is there a way around this permission problem?

Kind regards, 

More information about the Haskell-Cafe mailing list