
On Thu, Oct 18, 2012 at 5:03 PM, Jason Dusek
For diagnostic purposes, I'd like to print the PID of the process attached to this handle -- how best to do that?
In Mueval when I wanted the PID (so I could later send sigkills), I did this: hdl <- runProcess "mueval-core" args Nothing Nothing Nothing Nothing Nothing _ <- forkIO $ do threadDelay (7 * 700000) status <- getProcessExitCode hdl case status of Nothing -> do terminateProcess hdl _ <- withProcessHandle hdl (\x -> case x of OpenHandle pid -> signalProcess 9 pid >> return (undefined, undefined) _ -> return (undefined,undefined)) exitWith (ExitFailure 1) Just a -> exitWith a stat <- waitForProcess hdl exitWith stat The key is the poorly documented withProcessHandle :: System.Process.Internals.ProcessHandle -> (ProcessHandle__ -> IO (ProcessHandle__, a)) -> IO a The implementation: data ProcessHandle__ = OpenHandle PHANDLE | ClosedHandle ExitCode type PHANDLE = CPid Well, my code seems to work, anyway... -- gwern http://www.gwern.net