Created
December 19, 2017 20:13
-
-
Save niamtokik/03bbfbd3376b0f3013e2ae09c519a7cb to your computer and use it in GitHub Desktop.
Some experiment with System.Posix.Signals in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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