launchctl submit
應該已經再次運行該程序是否終止出於某種原因:
submit -l label [-p executable] [-o path] [-e path] -- command [args]
A simple way of submitting a program to run without a configura-
tion file. This mechanism also tells launchd to keep the program
alive in the event of failure.
-l label
What unique label to assign this job to launchd.
-p program
What program to really execute, regardless of what fol-
lows the -- in the submit sub-command.
-o path Where to send the stdout of the program.
-e path Where to send the stderr of the program.
,如果它出錯退出再次運行程序,設置保持活動的SuccessfulExit標準爲false:
<?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>test</string>
<key>ProgramArguments</key>
<array>
<string>bash</string>
<string>-c</string>
<string>n=$((RANDOM%2));say $n;exit $n</string>
</array>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
啓動節流閥作業,因此程序重新生成需要約10秒。
你爲什麼要這麼做?如果我知道你確切的問題,可能有另一種解決方案。 – jamespick
你是不是指'launchctl submit'?加載不會接受這些參數。在這種情況下,提交命令不支持間隔,因此您需要使用.plist版本。 – gaige
@gaige對不起,我做到了 – 735Tesla