
On 5 March 2011 21:43, Donn Cave
Quoth Bas van Dijk
, ... I understand why it's problematic to fork a process which is in the middle of running multiple simultaneous threads. However, in the case of a daemon the fork happens in the beginning of the program. So if I can manage to create a program that first daemonizes my process then starts the Haskell program, all is good.
type ProcessID = CInt type Fd = CInt
foreign import ccall "fork" c_fork :: IO CInt foreign import ccall "_exit" _exit :: CInt -> IO ()
fork :: IO Int -> IO ProcessID fork fn = do pid <- c_fork if pid == 0 then do fn >>= _exit . fromIntegral return 0 -- unused, I reckon else if pid > 0 then return pid else throwErrno "fork"
System.PosixProcess (exitImmediately) is supposed to be "_exit".
I would not care to hazard a guess as to whether this will work reliably for you.
Thanks, I thought about this too, however I consider myself too unfamiliar with the RTS to know if this is safe. Bas