Re: How to loop until kill command sent?
Re: How to loop until kill command sent?
- Subject: Re: How to loop until kill command sent?
- From: John Labovitz <email@hidden>
- Date: Mon, 16 Jul 2007 22:30:22 -0700
On Jul 16, 2007, at 9:05 PM, Devraj Mukherjee wrote:
1. How do I respond to kill signals sent to my application
2. Should I be using a threading model instead of the NSRunLoop
You shouldn't need to change to a threading model just to handle
signals. They aren't really that difficult. In fact, you should
treat signals as simply as possible, especially under Darwin, where
there are lots of operations that *can't* be done inside a signal
handler (unlike, say, Linux). The best thing to do is catch the
signal and somehow use a higher-level mechanism to eventually signal
your other code.
A while back I found some very useful code from Mike Laster that
implemented a safe mechanism for handling signals in a Cocoa app. He
describes it well:
Here is a trick that I came up with that seems to work for me. It
essentially captures a signal and safely transforms it
into a NSNotification which your code can register for to do
shutdown-oriented things. It seems that sending a Mach
message *IS* one of the few things you can safely do from the context
of a signal handler, so I took that and ran
with it.
Code & more explanation here:
http://www.cocoabuilder.com/archive/message/cocoa/2003/2/4/5786
As mentioned by another poster, you won't be able to catch SIGKILL or
SIGSTOP signals. However, if you catch SIGINT and SIGTERM, you'll
handle most termination conditions (see 'man signal' for more info).
--John
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden