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 초마다 로그에 기록하도록 시스템에 영향을 줍니까? 오류가 없으며 에이전트 자체가 정상적으로 작동하는 것 같습니다.



답변

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 프로그램이 끝날 때까지