launchd StartInterval changed behavior in 10.11?

According to the man(5) page for launchd.plist in El Capitan, StartInterval does not behave as it did in 10.9. I don't have 10.10 installed somewhere handy at the moment, so I can't tell if the same thing was stated in 10.10 also.


In 10.9, the man page states:

StartInterval <integer>

This optional key causes the job to be started every N seconds. If the system is asleep, the job will be started the next time the computer wakes up. If multiple intervals transpire before the computer is woken, those events will be coalesced into one event upon wake from sleep.


In 10.11, the man page says:

StartInterval <integer>

This optional key causes the job to be started every N seconds. If the system is asleep during the time of the next scheduled interval firing, that interval will be missed due to shortcomings in kqueue(3). If the job is running during an interval firing, that interval firing will likewise be

missed.


1. Is this a real change? I don't remeber hearing anything about it, and it's a rather large change in meaning of the StartInterval key.

2. If this is a real change, what is the suggested way of scheduling a job that must run at least X hours regardless of sleep?


Thanks,

Ryan

Replies

I don't have 10.10 installed somewhere handy at the moment, so I can't tell if the same thing was stated in 10.10 also.

The 10.10 man page has the same text as the 10.11 man page.

1. Is this a real change? I don't remeber hearing anything about it, and it's a rather large change in meaning of the StartInterval key.

I suspect it’s a documentation change to make it more accurately reflect reality.

2. If this is a real change, what is the suggested way of scheduling a job that must run at least X hours regardless of sleep?

regardless of sleep would imply that you want to wake the Mac so that launchd can run your job. launchd has never had that ability. You can, however, schedule wakes using

IOPMSchedulePowerEvent
.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks Quinn. Should've been more clear. When I say "regardless of sleep" I meant how do I achieve the behavior that was documented (but perhaps never really worked) in 10.10 and before...start a job every X hours, and if the machine is asleep during the next scheduled interval, start the job when the machine wakes up.


I can schedule it to start much more frequently (e.g. every hour or so instead of every 8 hours) but that seems wasteful. The only other thing I can think of is to add several StartCalendarInterval schedules that start the job at a specific time, since that seems to still start the job the next time the machine is awake if it is asleep during an interval.

What does this job do? Reading between the lines, I can’t help but thingk that XPC activity would be a better option here. Watch WWDC 2013 Session 702 Efficient Design with XPC for the background to this.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Ideally we would use xpc_activity, but unfortunately there's two issues. One, we still support 10.7 and 10.8. Two, this job doesn't need to to run for a long time, all the time (e.g. a true daemon). It loads, looks at a list of things it must submit to some servers (think software update type of service), and uploads them to a server. The whole operation generally takes 500-750 milliseconds depending on server latency. So having it loaded all the time seems wasteful.

One, we still support 10.7 and 10.8.

I can’t help you with that one. Although I should point out that Mac system requirements haven’t changed since 10.8, so you can drop 10.7 (released 2011) then there’s not much holding folks on 10.8.

Two, this job doesn't need to to run for a long time, all the time (e.g. a true daemon). It loads, looks at a list of things it must submit to some servers (think software update type of service), and uploads them to a server. The whole operation generally takes 500-750 milliseconds depending on server latency. So having it loaded all the time seems wasteful.

XPC activity does not require the job to be loaded all the time.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"