[Haskell-cafe] how to implement daemon start and stop directives?
lambda-belka at yandex.ru
Thu Jan 22 03:11:39 EST 2009
> You can abstract this pattern:
> -- runs its argument in an infinite loop, and returns an action that stops
> the loop
> daemon :: IO () -> IO (IO ())
> daemon action = do
> stopvar <- atomically $ newTVar False
> let run = do
> stop <- atomically $ readTVar stopvar
> if stop then return () else (action >> run)
> forkIO run
> return (atomically $ writeTVar stopvar True)
> TVars are overkill here, actually, an IORef would be just fine, I think.
Why do you write "return (atomically $ writeTVar stopvar True)" in the end?
Actually, I'm more interested in technical details how to communicate from
shell with background process - how to send commands to it. Currently
looking into POSIX libraries hope to find answers there...
Also, maybe a FIFO-pipe-file would solve my problem. Imagine writing a
command in it, while one of daemon's thread is locked-while-awaits for
anything to come out from the other side of the pipe...
View this message in context: http://www.nabble.com/how-to-implement-daemon-start-and-stop-directives--tp21598690p21599567.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe