Re: [Haskell-beginners] forkIO and signal handlers

Thanks for the reply. The problem isn't signal handling, nor is it
using forkIO. It's using both of them together.
On Fri, Sep 9, 2011 at 12:14 PM, Tim Perry
There is an example of forking processes in the "Real World Haskell" book in chapter 20 - Systems Programming. http://book.realworldhaskell.org/read/systems-programming-in-haskell.html
Unfortunately I don't think it covers catching signals. I hope this helps. Tim ________________________________ From: Michael Litchard
To: beginners@haskell.org Sent: Friday, September 9, 2011 12:06 PM Subject: [Haskell-beginners] forkIO and signal handlers I am trying to use installHandler with forkIO. I'd like to fork a process in Main when a signal is caught, having trouble with the types and I'm sure there is a convention I'm not familiar with. Could I see an example of how this is done?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Fri, Sep 9, 2011 at 15:35, Michael Litchard
Thanks for the reply. The problem isn't signal handling, nor is it using forkIO. It's using both of them together.
I think you'll have to provide an example of what you're trying to do and the error message you get. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Here's the error message. The problem is clear, not sure what to do about it. My broken code should show my intent though.
main :: IO () main = do let world = (newEmptyTMVar :: ProcessState) let jCount = (newEmptyTMVar :: JobCount) installHandler userDefinedSignal1 (forkIO $ Catch $ worldHandler world jCount) Nothing sequence_ $ repeat $ worldCheck
I'd like to fork in Main. Right now I'm forking in worldHandler. If
that's what I have to do, then I'll just move on. But I'd like to keep
the forkIO call in Main if possible.
On Fri, Sep 9, 2011 at 12:46 PM, Brandon Allbery
On Fri, Sep 9, 2011 at 15:35, Michael Litchard
wrote: Thanks for the reply. The problem isn't signal handling, nor is it using forkIO. It's using both of them together.
I think you'll have to provide an example of what you're trying to do and the error message you get. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

forgot to paste in the error message, oops
copy_take.lhs:48:51:
Couldn't match expected type `IO ()' with actual type `Handler'
In the second argument of `($)', namely
`Catch $ worldHandler world jCount'
In the second argument of `installHandler', namely
`(forkIO $ Catch $ worldHandler world jCount)'
In a stmt of a 'do' expression:
installHandler
userDefinedSignal1
(forkIO $ Catch $ worldHandler world jCount)
Nothing
Failed, modules loaded:
On Fri, Sep 9, 2011 at 12:53 PM, Michael Litchard
Here's the error message. The problem is clear, not sure what to do about it. My broken code should show my intent though.
main :: IO () main = do let world = (newEmptyTMVar :: ProcessState) let jCount = (newEmptyTMVar :: JobCount) installHandler userDefinedSignal1 (forkIO $ Catch $ worldHandler world jCount) Nothing sequence_ $ repeat $ worldCheck
I'd like to fork in Main. Right now I'm forking in worldHandler. If that's what I have to do, then I'll just move on. But I'd like to keep the forkIO call in Main if possible.
On Fri, Sep 9, 2011 at 12:46 PM, Brandon Allbery
wrote: On Fri, Sep 9, 2011 at 15:35, Michael Litchard
wrote: Thanks for the reply. The problem isn't signal handling, nor is it using forkIO. It's using both of them together.
I think you'll have to provide an example of what you're trying to do and the error message you get. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Handler is not IO (), it is a handler. Try this:
installHandler userDefinedSignal1 (Catch (forkIO (worldHandler world
jCount) >> return ())) Nothing
On Fri, Sep 9, 2011 at 3:54 PM, Michael Litchard
forgot to paste in the error message, oops
copy_take.lhs:48:51: Couldn't match expected type `IO ()' with actual type `Handler' In the second argument of `($)', namely `Catch $ worldHandler world jCount' In the second argument of `installHandler', namely `(forkIO $ Catch $ worldHandler world jCount)' In a stmt of a 'do' expression: installHandler userDefinedSignal1 (forkIO $ Catch $ worldHandler world jCount) Nothing Failed, modules loaded:
On Fri, Sep 9, 2011 at 12:53 PM, Michael Litchard
wrote: Here's the error message. The problem is clear, not sure what to do about it. My broken code should show my intent though.
main :: IO () main = do let world = (newEmptyTMVar :: ProcessState) let jCount = (newEmptyTMVar :: JobCount) installHandler userDefinedSignal1 (forkIO $ Catch $ worldHandler world jCount) Nothing sequence_ $ repeat $ worldCheck
I'd like to fork in Main. Right now I'm forking in worldHandler. If that's what I have to do, then I'll just move on. But I'd like to keep the forkIO call in Main if possible.
On Fri, Sep 9, 2011 at 12:46 PM, Brandon Allbery
wrote: On Fri, Sep 9, 2011 at 15:35, Michael Litchard
wrote: Thanks for the reply. The problem isn't signal handling, nor is it using forkIO. It's using both of them together.
I think you'll have to provide an example of what you're trying to do and the error message you get. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (3)
-
Brandon Allbery
-
David McBride
-
Michael Litchard