[launchd-dev] Restrict so only one instance runs

Dave Zarzycki zarzycki at apple.com
Wed Aug 27 12:29:19 PDT 2008


On Aug 27, 2008, at 11:28 AM, Crawford Kyle wrote:

> Hello,
>
> I often need to schedule scripts to run at an interval, but I don't
> know how long that script will take to complete and I don't want the
> script to run again at its normal interval unless the script isn't
> running.
>
> I've done this with pid files and grepping through ps lists to exit
> the script if another instance is running, but I was wondering if
> there is something built into launchd to handle this.
>
> I tried combining LaunchOnlyOnce with StartInterval, but with
> LaunchOnlyOnce, it seems that the job gets unloaded as soon as it
> runs, so the interval becomes pretty meaningless.
>
> Is there a way to do this with launchd?  Should there be a way to do
> this with launchd?


What you want is implicit with launchd. LaunchOnlyOnce will eventually  
get renamed to "HopefullyNeverExits" Just setup a StartInterval and  
you're set. If the job is still running, launchd will not start a  
second copy.

davez



More information about the launchd-dev mailing list