launchd – launchctl and sleep states

[ad_1]

From the launchd.plist(5) man web page:

StartInterval <integer>
 This non-obligatory key causes the job to be began each N seconds. If the
 system is asleep in the course of the time of the subsequent scheduled interval firing,
 that interval might be missed because of shortcomings in kqueue(3).  If the
 job is operating throughout an interval firing, that interval firing will
 likewise be missed.

StartCalendarInterval <dictionary of integers or array of dictionaries of
 integers>
 This non-obligatory key causes the job to be began each calendar interval as
 specified. Lacking arguments are thought of to be wildcard. The semantics
 are much like crontab(5) in how firing dates are specified. A number of
 dictionaries could also be laid out in an array to schedule a number of calendar
 intervals.

 In contrast to cron which skips job invocations when the pc is asleep,
 launchd will begin the job the subsequent time the pc wakes up.  If
 a number of intervals transpire earlier than the pc is woken, these occasions
 might be coalesced into one occasion upon wake from sleep.

Instance, to run a job each 4 hours beginning at midnight day by day:

<key>StartCalendarInterval</key>
<array>
    <dict>
        <key>Hour</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>Hour</key>
        <integer>4</integer>
    </dict>
    <dict>
        <key>Hour</key>
        <integer>8</integer>
    </dict>
    <dict>
        <key>Hour</key>
        <integer>12</integer>
    </dict>
    <dict>
        <key>Hour</key>
        <integer>16</integer>
    </dict>
    <dict>
        <key>Hour</key>
        <integer>20</integer>
    </dict>
</array>

There could also be a bug in launchd that can trigger the job to run at an offset to the occasions specified, relying on the time zone, however that should not matter to your functions.

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *