#1842: runInteractiveCommand should install SIGCHLD handler
--------------------------+-------------------------------------------------
Reporter: firefly | Owner:
Type: bug | Status: new
Priority: normal | Component: libraries/base
Version: 6.8.1 | Severity: normal
Keywords: fork, SIGCHLD | Architecture: Unknown
Os: Multiple |
--------------------------+-------------------------------------------------
Testcase:
module Main where
-- Test case for process fork/SIGCHLD bug
-- 2007-11-07 Peter Lund <[EMAIL PROTECTED]>
--
-- 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 <mumble>
-- (+ 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 ()
}
--------------------------+-------------------------------------------------
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.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1842>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs