使用 launchd 限制发送到终端的重生消息:这是正常的吗?

使用 launchd 限制发送到终端的重生消息:这是正常的吗?

launchd使用 WatchPaths 功能设置了一个代理。它看起来像

<?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>com.my.label</string>
    <key>LowPriorityIO</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>PROGRAM HERE</string>
    </array>
    <key>QueueDirectories</key>
    <array/>
    <key>ThrottleInterval</key>
    <integer>10</integer>
    <key>WatchPaths</key>
    <array>
        <string>PATH HERE</string>
    </array>
</dict>
</plist>

每隔 10 秒,我就会收到一条控制台消息,例如

com.apple.launchd.peruser.501: (com.my.label) Throttling respawn: Will start in 10 seconds

这是正常的吗?每 10 秒将这些消息写入日志会影响我的系统吗?没有错误,代理本身似乎运行良好。

答案1

launchd 最多每 10 秒才会启动一次程序。来自man launchd.plist

ThrottleInterval <integer>
This key lets one override the default throttling policy imposed on jobs
by launchd.  The value is in seconds, and by default, jobs will not be
spawned more than once every 10 seconds.  The principle behind this is
that jobs should linger around just in case they are needed again in the
near future. This not only reduces the latency of responses, but it
encourages developers to amortize the cost of program invocation.

如果 WatchPaths 中的文件在上次调用后 10 秒内被修改,则作业受到限制是正常的。将 ThrottleInterval 设置为低于 10 的值不会产生任何效果。

如果您想删除这些日志消息,请sleep 10在程序末尾添加类似的内容。

相关内容