Skip to content
Tutorials Center
My learning

Topics

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.

Terminal
nproc [--all] [--ignore=N]

Try it

Bash Basic use and options

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.

Bash Sizing parallel work

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

Terminal
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 nproc prints 2 even on a 16-CPU machine. Containers restricted with --cpuset-cpus behave 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_THREADS and OMP_THREAD_LIMIT override the result without --all. This is by design so that tools calling nproc follow the same limits as OpenMP programs.
  • Build recipe: make -j"$(nproc)", or make -j"$(( $(nproc) + 1 ))" for builds that wait on disk. Use --ignore=1 on a shared workstation.
  • Not portable: nproc is GNU coreutils. On macOS use sysctl -n hw.ncpu; a portable fallback is getconf _NPROCESSORS_ONLN (see getconf).
  • For the full hardware picture (sockets, threads, caches), use lscpu.