nproc: How Many CPUs the Runner Really Has
nproc prints the number of processing units available to the current process, the right input for make -j and test parallelism.
Setting build parallelism by hand wastes cores or oversubscribes the runner. nproc reports what is actually available, including respecting cgroup CPU limits, which is exactly what you want to feed -j.
What it does
nproc returns the count of CPUs available to the process, honoring the CPU affinity mask. --all reports every CPU the machine has, ignoring affinity and cgroup restrictions. The difference matters in containers, where the host may have 32 cores but the container is limited to 2.
Common usage
nproc # CPUs available to this process
nproc --all # total CPUs on the machine
make -j"$(nproc)" # parallelize a build to all cores
ctest -j"$(nproc)" # parallel test runOptions
| Flag | What it does |
|---|---|
| (none) | CPUs available to the current process |
| --all | All CPUs present, ignoring affinity/limits |
| --ignore=<N> | Subtract N from the count (leave headroom) |
In CI
Use nproc (not --all) to size parallelism so the value respects the runner’s CPU quota. Be aware that older nproc and many language runtimes ignore cgroup CPU limits and report the host count, leading a 2-CPU container to spawn 32 build jobs and thrash. When in doubt, leave headroom with nproc --ignore=1.
Common errors in CI
Oversubscription is the classic symptom: a container limited to 2 CPUs but reporting 32 from nproc --all (or from Node’s os.cpus()) spawns far too many workers, the load average spikes, and the build slows down or OOMs. Prefer plain nproc, or read /sys/fs/cgroup/cpu.max to compute the real quota.