Skip to content

Instantly share code, notes, and snippets.

@niamtokik
Created December 19, 2017 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niamtokik/03bbfbd3376b0f3013e2ae09c519a7cb to your computer and use it in GitHub Desktop.
Save niamtokik/03bbfbd3376b0f3013e2ae09c519a7cb to your computer and use it in GitHub Desktop.
Some experiment with System.Posix.Signals in Haskell
module Main where
import System.Posix
import System.Posix.IO
import System.Posix.Signals
test childRead fatherWrite = do
(r, _) <- fdRead childRead 10
putStrLn r
childHandler = do
putStrLn "call"
raiseSignal sigKILL
fatherLoop fdr fdw = do
installHandler sigCHLD (CatchOnce childHandler) Nothing
putStrLn "fatherLoop"
fdWrite fdw "test"
fdWrite fdw "exit"
fatherLoop fdr fdw
childLoop fdr fdw = do
putStrLn "childLoop"
(r, c) <- fdRead fdr 4
case r of
"exit" -> putStrLn "done" >> raiseSignal sigCHLD
otherwise -> putStrLn r >> childLoop fdr fdw
main :: IO ()
main = do
putStrLn "Hello, Haskell!"
(fatherRead, fatherWrite) <- createPipe
(childRead, childWrite) <- createPipe
x <- forkProcess $ childLoop childRead fatherWrite
fatherLoop fatherRead childWrite
putStrLn "stop"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment