Re: Launchd daemon
Re: Launchd daemon
- Subject: Re: Launchd daemon
- From: Jens Alfke <email@hidden>
- Date: Mon, 18 Mar 2013 10:05:25 -0700
On Mar 18, 2013, at 8:36 AM, Erwin Namal < email@hidden> wrote: Sorry. I meant How do I handle SIGTERM?
You can register a signal handler with your kqueue. When SIGTERM is sent, your handler gets invoked and can run your cleanup code and then call exit().
Sounds like you should read up on kqueues. (I am not sure how much Darwin-specific documentation there is. I believe the core technology came from BSD, so there are probably various BSD-related docs floating around the Interwebs.)
In a nutshell, kqueues are very much like NSRunLoop. You create a queue, register handlers for various events like signals and I/O, then start the loop and let it run forever.
- How to set up my project to use Objective-C for my daemon.
Just create a new project and choose the “Command-Line Tool” template. Then add .m files to it. - What does my Objective-C entry point look like (int main(…) ?)
Yeah, a main() function.
Just be aware that any place you’ve got a C-level callback that runs Obj-C code, wrap its body with @autorelease{…} to make sure objects autoreleased inside it get cleaned up. Same thing applies to setup code you run before dropping into the kqueue loop.
—Jens |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden