What is the best practice for creating a daemon with launchd that runs at lower than default priority
I have a daemon I would like have to parallelize up to the number of cores on a user's machine, but I don't want it interfering with foreground tasks. Traditionally, in unix, I would just run this daemon at nice=1, e.g.
nohup nice -n 1 MyDaemon &
The Apple launchd plist documentation features several items that speak to priority issues, but they're vaguely defined, specifically,
ProcessType=Background
LowPriorityIO=true
Nice=N
Is there someplace where the exact behavior of ProcessType=Background is defined? It would seem that it may be "smarter" than just setting Nice and LowPriorityIO.
Solution 1:
Summarized from man launchd.plist
:
LowPriorityBackgroundIO: Specifies whether the kernel should consider this daemon to be low priority when doing file system I/O when the process is throttled with Darwin-background classification.
ProcessType: This optional key describes, at a high level, the intended purpose of the job. The system will apply resource limits based on what kind of job it is. If left unspecified, the system will apply light resource limits to the job, throttling its CPU usage and I/O bandwidth.
ProcessType=Background: Background jobs are generally processes that do work that was not directly requested by the user. The resource limits applied to the Background are intended to prevent them from disrupting the user experience.