[launchd-dev] Programmatic interface to launchctl and some other questions, OS X 10.5

Damien Sorresso dsorresso at apple.com
Tue Oct 26 11:12:25 PDT 2010


On Oct 26, 2010, at 10:50 AM, Rainer Brockerhoff wrote:
> At 05:49 -0700 26/10/10, launchd-dev-request at lists.macosforge.org wrote:
>> Date: Tue, 26 Oct 2010 10:13:09 +0100
>> From: "Quinn \"The Eskimo!\"" <eskimo1 at apple.com>
>> Message-ID: <AAB6BEB9-F4AF-4B93-A3D6-E49DB5C0ECC2 at apple.com>
>> 
>> On 26 Oct 2010, at 03:55, Jerry Krinock wrote:
>> 
>>> On 2010 Oct 25, at 18:01, eveningnick eveningnick wrote:
>>> 
>>>> Also there's a /usr/include/launch.h file, which provides some kind of
>>>> API, but i've no idea how to use it, and i am not sure if it gives any
>>>> means to load/start/stop/unload agents. Maybe i could use it somehow?
>>> 
>>> Anyone know what he's talking about?
>> 
>> The routines in <launch.h> provide necessary services for launchd jobs (daemons and agents).  Specifically, a launchd job uses this API to check in with launchd.  See SampleD for an example of this.
>> 
>> <http://developer.apple.com/library/mac/#samplecode/SampleD/>
>> 
>> If you need to manipulate the launchd state, you should use Service Management (if it's available and does what you want) or simply fork/exec launchctl.  And yes, it is both sad and a chore )-:
> 
> As a footnote to Quinn's reply, check out my post about using the launch.h API to check if your agent is running:
> http://brockerhoff.net/blog/2009/02/02/cocoa-musings-pt-3/
> 
> This does work under 10.5.


The idea of "is running" is race-prone. Jobs should advertise a service that is present whether or not there is a process running to back it.

Also, there is no guarantee that those APIs will return the PID. There's really no guarantee about anything they'll return except in the use case illustrated by SampleD.
-- 
Damien Sorresso
BSD Engineering
Apple Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/launchd-dev/attachments/20101026/b70041b9/attachment.html>


More information about the launchd-dev mailing list