Build system priority execution

When doing large builds on a computer that’s also used for interactive tasks (say, a developer laptop), the system may feel sluggish to the user while building. Likewise, running tests can take a lot of CPU time and make the system less responsive. To mitigate the high CPU usage, the run priority of the build system or test runner can be lowered. This does not help if the system is running out of RAM or has low disk IOPS, but it can help if the system is CPU-bound. Running at a lower priority can be more efficient than simply hard-limiting the number of CPU cores used by the build system or test runner.

These examples apply to virtually any build system such as CMake or Meson.

On Unix-like systems (Linux, macOS, BSD, …) use nice to control process priority.

nice -n 19 cmake --build build

nice -n 19 meson compile -C build
nice -n 19 ctest --test-dir build

nice -n 19 meson test -C build
nice -n
run task(s) with priority, where bigger positive numbers are lower priority, and more negative numbers are higher priority.

On Windows the start command can control process priority.

start /low cmake --build build

start /low meson compile -C build
start /low ctest --test-dir build

start /low meson test -C build
start /low
runs a program and its child processes at low priority.