Skip to content

Instantly share code, notes, and snippets.

@greydot
Created May 29, 2016 19:57
Show Gist options
  • Save greydot/8fe49b2c75dab8c35914ac008fb6828d to your computer and use it in GitHub Desktop.
Save greydot/8fe49b2c75dab8c35914ac008fb6828d to your computer and use it in GitHub Desktop.
Segfaults somewhere between 500 and 1000 iterations.
import Control.Monad (when)
import System.Exit (exitSuccess)
import System.Posix.Process (forkProcess)
fork_ :: Integer -> IO ()
fork_ n | n > 0 = do pid <- forkProcess (fork_ $ n - 1)
when (pid /= 0) exitSuccess
| otherwise = putStrLn "I'm done!"
main :: IO ()
main = fork_ 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment