Linux Command Reference ยท System Information
Linux nproc command
Reference for the Linux nproc command: print the number of processing units available to a process, use --all and --ignore, and size parallel jobs.
nproc prints a single number: how many processing units (logical CPUs) the current process may use. It is the right value to hand to make -j, xargs -P or any program that asks how many worker processes to start.
By default it respects the CPU affinity of the process (set by taskset, containers or job schedulers) and the OMP_NUM_THREADS family of variables. That makes it more useful than counting lines in /proc/cpuinfo.
nproc [--all] [--ignore=N]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
nproc [OPTION]...
| Option | Description |
|---|---|
--all |
Print the number of installed processing units, ignoring affinity and environment limits. |
--ignore=N |
Subtract N from the count, but never print less than 1. |
--help, --version |
Usual information options. |
Returns: the count on standard output; exit status 0. A bad --ignore value gives an error and status 1.
Usage notes
- Logical CPUs, not cores. With hyper-threading, a 4-core CPU reports 8. For CPU-bound jobs this is usually still the best default; memory-heavy builds may want fewer.
- Affinity aware:
taskset -c 0-1 nprocprints 2 even on a 16-CPU machine. Containers restricted with--cpuset-cpusbehave the same way. - Quotas are invisible. A container limited to "1.5 CPUs" through a CPU quota (not a cpuset) still sees all CPUs in
nproc. Programs that must honor quotas have to read the cgroup files. OMP_NUM_THREADSandOMP_THREAD_LIMIToverride the result without--all. This is by design so that tools callingnprocfollow the same limits as OpenMP programs.- Build recipe:
make -j"$(nproc)", ormake -j"$(( $(nproc) + 1 ))"for builds that wait on disk. Use--ignore=1on a shared workstation. - Not portable:
nprocis GNU coreutils. On macOS usesysctl -n hw.ncpu; a portable fallback isgetconf _NPROCESSORS_ONLN(seegetconf). - For the full hardware picture (sockets, threads, caches), use
lscpu.