The "daemons must live for at least 60 seconds" factoid
It's a commonly repeated piece of folklore that if your launchdaemon completes in under 60 seconds, launchd will assume it has crashed and will re-launch it. I have a LaunchAgent with a 2 minute StartInterval, which exits quickly if there are no available jobs for it to work on. launchd tends to run it once due to the StartInterval, then again 15 seconds later - presumably because it didn't live for at least 60 seconds. Adding "sleep(60)" to the end of my LaunchAgent seems to prevent it from launching the 2nd time around. However, I can't find any actual documentation that mentions this, and I'm sure I've heard somewhere that it was a Tiger bug/feature only, due to be fixed in Leopard - this appears to not be the case. It seems an odd feature, too - why relaunch something that exited with a successful status code? Is there any official documentation of this behaviour? -Jonathan del Strother
In general, launchd does not relaunch processes which exit successfully. It would help if you shared the relevant portions of your launchd plist. Kevin On Aug 19, 2009, at 5:16 AM, Jonathan del Strother wrote:
It's a commonly repeated piece of folklore that if your launchdaemon completes in under 60 seconds, launchd will assume it has crashed and will re-launch it. I have a LaunchAgent with a 2 minute StartInterval, which exits quickly if there are no available jobs for it to work on. launchd tends to run it once due to the StartInterval, then again 15 seconds later - presumably because it didn't live for at least 60 seconds. Adding "sleep(60)" to the end of my LaunchAgent seems to prevent it from launching the 2nd time around.
However, I can't find any actual documentation that mentions this, and I'm sure I've heard somewhere that it was a Tiger bug/feature only, due to be fixed in Leopard - this appears to not be the case. It seems an odd feature, too - why relaunch something that exited with a successful status code?
Is there any official documentation of this behaviour?
-Jonathan del Strother
Thanks for the reply - turns out that it's being relaunched because launchd thinks one of the watch paths changed. I'm not sure why - to the best of my knowledge it's been read from, but not written to - but at least it clears up one mystery. It's actually monitoring a sqlite database - maybe sqlite is invisibly writing to it behind the scenes, I'll see if I can find anything with instruments... On Wed, Aug 19, 2009 at 6:16 PM, Kevin Van Vechten<kvv@apple.com> wrote:
In general, launchd does not relaunch processes which exit successfully.
It would help if you shared the relevant portions of your launchd plist.
Kevin
On Aug 19, 2009, at 5:16 AM, Jonathan del Strother wrote:
It's a commonly repeated piece of folklore that if your launchdaemon completes in under 60 seconds, launchd will assume it has crashed and will re-launch it. I have a LaunchAgent with a 2 minute StartInterval, which exits quickly if there are no available jobs for it to work on. launchd tends to run it once due to the StartInterval, then again 15 seconds later - presumably because it didn't live for at least 60 seconds. Adding "sleep(60)" to the end of my LaunchAgent seems to prevent it from launching the 2nd time around.
However, I can't find any actual documentation that mentions this, and I'm sure I've heard somewhere that it was a Tiger bug/feature only, due to be fixed in Leopard - this appears to not be the case. It seems an odd feature, too - why relaunch something that exited with a successful status code?
Is there any official documentation of this behaviour?
-Jonathan del Strother
At 14:33 +0100 20/8/09, Jonathan del Strother wrote:
It's actually monitoring a sqlite database - maybe sqlite is invisibly writing to it behind the scenes, I'll see if I can find anything with instruments...
It's likely that <x-man-page://1/fs_usage> will also be instructive in this case. S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
In addition to what Kevin said... At 13:16 +0100 19/8/09, Jonathan del Strother wrote:
It's a commonly repeated piece of folklore that if your launchdaemon completes in under 60 seconds, launchd will assume it has crashed and will re-launch it.
I think this folklore is a bit mixed up. It's not that launchd assumes that the job crashed, and thus relaunches it, it's that launchd will /prevent/ it from being launched again too quickly. In modern versions of launchd (10.5 and later?) the value changed (to 10 seconds) and you can control the value on a job-by-job basis with the ThrottleInterval key (see <x-man-page://5/launchd.plist> for details). S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
participants (3)
-
Jonathan del Strother
-
Kevin Van Vechten
-
Quinn