I've written a launch agent:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.mylaunchagent.plist</string>
<key>ProgramArguments</key>
<array>
<string>~/my_script.sh</string>
</array>
<key>StartInterval</key>
<integer>12</integer>
<key>StandardOutPath</key>
<string>~/my_log_file</string>
<key>StandardErrorPath</key>
<string>~/my_err_file</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
It works, but it runs every 22 seconds instead of every 12 seconds, because ~/my_script.sh
takes 10 seconds to finish.
launchd seems to be adding the interval time and the execution time together, even though I want the program to be run every interval. I don't want launchd to wait for it to finish.
So I tried running the program in the background:
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>-c</string>
<string>~/my_script.sh & disown</string>
</array>
But now I don't get any output at all, so I suspect that launchd kills all spawned processes as soon as the process that it launched exits.
So my question is, how can I start a slow command (takes an unpredictable 10+ seconds to finish) every 12 seconds reliably?
StartCalendarInterval
in the man page.