[launchd-dev] How to ensure that my job is launched through launchd and not directly?

Per Olofsson per.olofsson at gu.se
Thu Apr 16 06:53:27 PDT 2015


16 apr 2015 kl. 13:25 skrev Raunak Poddar <raunak.poddar at gmail.com>:
> 
> I have a program and I want to ensure that it has been launched only by launchd (as a daemon) & it should terminate if the user launches it directly (double-click on Finder, terminal). Is there a nifty way of accomplishing this?

A quick and dirty check would be to use getppid() and ensure that it's launchd. A better way is probably to check in with launchd (see SampleD.c), but I'm not actually sure what happens if you run that manually.

-- 
Per Olofsson, IT-service, University of Gothenburg



More information about the launchd-dev mailing list