Re: Launchd daemon
Re: Launchd daemon
- Subject: Re: Launchd daemon
- From: Tilghman Lesher <email@hidden>
- Date: Mon, 18 Mar 2013 10:23:06 -0500
On Mon, Mar 18, 2013 at 6:47 AM, Erwin Namal <email@hidden> wrote:
> Have you read this?
>
> <http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html>
>
>
> Yes, this is where they explain all about the plists. It is very well
> documented, but doesn't answer my questions which are:
> - How to set up my project to use Objective-C for my daemon.
> - What does my Objective-C entry point look like (int main(…) ?)
Basically, structure it the same wait that you thought, but instead of
using a sleep(), use kqueue() to receive events from the kernel. When
there are no events, your process stays suspended.
> - How do I handle SIGKILL
You cannot. SIGKILL, by definition, is not handle-able. If sent to
your process, your process will never receive it, but it will stop
running and be removed from memory. Therefore, if you have any
resources that you need to shut down or close in a special way, it's
critical that you do so in the timeframe allotted between the TERM and
the KILL.
> - If I can't use a for/while/etc. loop, how do I prevent my daemon from
> exiting once the main function returns?
Set up kqueue() prior to your loop, then call it at the top of your
loop and use a switch statement (or multiple if/else conditions) to
handle each type of event coming back from kqueue(). After you've
handled one event, you can loop back to call kqueue() again, for the
next event.
_______________________________________________
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