runInteractiveCommand should install SIGCHLD handler
System.Process contains simple functions for running external commands. It should be usable all on its own, without having to tinker with System.Posix.Signals.
If runInteractiveCommand executes a command that terminates too quickly AND the parent process hasn't reached its waitForProcess yet, THEN the parent receives SIGCHLD. If there is no handler installed for that signal, the runtime just dies abruptly.
If the parent makes it to the waitForProcess in time then everything is fine and dandy.
As far as I can tell, the runtime system itself never installs a SIGCHLD handler and neither does the code in System.Process.
As an aside, I wonder how getProcessExitCode ever worked.
Trac metadata
Trac field | Value |
---|---|
Version | 6.8.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | module Main where |
-- Test case for process fork/SIGCHLD bug | |
-- 2007-11-07 Peter Lund firefly@vax64.dk | |
-- | |
-- compile with one of: | |
-- ghc --make bug | |
-- ghc -threaded --make bug # this will crash faster | |
-- | |
-- run with: | |
-- ./bug | |
-- | |
-- expected result: | |
-- a long list of numbers + "ok" | |
-- | |
-- actual result: | |
-- the program abruptly stops with exit code 141 (echo $?) which is SIGCHLD | |
-- | |
-- tested with (with or without the hClose calls): | |
-- ghc 6.6.1 on Ubuntu Gutsy Gibbon | |
-- ghc 6.8.1 on Ubuntu Gutsy Gibbon | |
-- ghc 6.6 on Ubuntu Feisty Fawn | |
-- ghc 6.4.2 on Gentoo | |
-- (+ ghci versions of above) |
import System.IO import System.Process
runTest :: String -> IO () runTest s = do{ print s ; (inp, out, err, ph) <- runInteractiveCommand ("true") ; hPutStr inp s ; waitForProcess ph ; hClose inp ; hClose out ; hClose err ; return () }
main :: IO () main = do{ mapM_ runTest (map show [1..1000]) ; putStrLn "OK" ; return () } | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | Multiple | | Architecture | Unknown |