brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: taskpolicy -b runs a heavy command at background priority on your Mac

Terminal
~/tips/tip-macos-taskpolicy-background-priority

taskpolicy -b ./convert-all.sh

Runs a command or an already running process at low background priority.

Some commands happily take every core they can get, and then the rest of the Mac feels sluggish. taskpolicy lets me say that a job can wait.

Put it in front of the command you start:

taskpolicy -b ./convert-all.sh

According to the man page, -b runs the program after calling setpriority(2) with PRIO_DARWIN_BG. The page also says all children of the program inherit these policies, so a script that starts other tools carries the setting along. If you want a quality-of-service clamp instead, -c accepts utility, background or maintenance:

taskpolicy -c utility ./convert-all.sh

Disk access has its own switch. -d takes an I/O policy that can be a number or a name such as default or throttle:

taskpolicy -d throttle ./convert-all.sh

For a job that is already running, find its process ID and change it afterwards. -B with -p takes the process out of background mode again:

taskpolicy -b -p 1234
taskpolicy -B -p 1234

The 1234 is a placeholder, so look up the real ID with pgrep or Activity Monitor.

The caveat is the trade-off. Background priority is meant to give way to other work, so a long conversion can take longer than it would at normal priority. That is the point, but plan for it before you start something you need done in ten minutes.

Further reading: taskpolicy man page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link