Re: Launchd daemon
Re: Launchd daemon
- Subject: Re: Launchd daemon
- From: Nick Blievers <email@hidden>
- Date: Sun, 17 Mar 2013 16:32:00 -0500
- Acceptlanguage: en-US
- Thread-topic: Launchd daemon
On 18/03/2013, at 7:59 AM, Erwin Namal wrote:
> Hello,
>
> I have a large experience in developing cocoa applications, but none with launchd daemons. I would like to develop a system daemon running from start to shutdown and I know, from the documentation below [1] that there are a few requirements.
> I have tried to compile the sampleD daemon, but it is way outdated and I can't make it work… despite setting it to 64bits and mountain lion.
> So I have a few questions:
>
> 1. Which language can I use for my daemon? Obj-C? C? C++?
> 2. Is there a specific template to use? I saw an XPC service template in Xcode but that's all.
> 3. I know I need to handle SIGTERM, but I don't know how. Are there any other requirements?
> 4. I think that once launched, the daemon must have an infinite loop, right? ShouldI put a sleep() call inside? If yes, for how long?
>
> These are pretty basic questions. I will gladly take any help, any sample code or any link towards documentations… in short amything is good to help me start.
launchd doesn't care what language you use, or how you structure you daemon. For the most part, ignore launchd and write your deamon how you would normally. The one difference you for a launchd daemon vs a normal daemon that you should care about, is the way it handles sockets. That is, launchd itself handles the basic socket code (if your daemon uses sockets).
So, to answer your specific questions:
1. Any.
2. No.
3. Not really, you can (and should) have launchd handle the listening sockets (if any)
More info here:
http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html
4. Polling is typically not what you want (sleep implies polling), you want to listen for events and react when they occur. One nice thing with launchd is you can have a daemon that reacts to socket events, and the daemon itself can actually stop running and be fired up by launchd when a socket event occurs.
Have a read through the documentation, it has most of the information you need
Hope this helps,
Nick
_______________________________________________
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