← 返回命令列表

Linux command

nproc 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Print number of processing units

nproc

Print all installed processors

nproc --all

Print number minus N

nproc --ignore [2]

Use in make for parallel jobs

make -j$(nproc)

说明

nproc prints the number of processing units available to the current process. This is useful for parallelizing builds and other workloads. By default, nproc respects cgroup limits, returning the number of CPUs available within containerized environments. This makes it container-aware - a container limited to 4 CPUs will see 4, not the host's full CPU count. The --all option ignores cgroup limits and returns the total number of installed processors. This is useful when you need to know the actual hardware regardless of containerization. Combined with --ignore, you can reserve CPUs for system tasks. For example, `nproc --ignore=1` leaves one core free. Common usage is setting parallel build jobs: `make -j$(nproc)` compiles with one job per available processor. This maximizes build speed while respecting system limits.

参数

--all
Print total number of installed processors, ignoring cgroup limits.
--ignore= _N_
Exclude N processors from count.
--help
Display help.
--version
Display version.

FAQ

What is the nproc command used for?

nproc prints the number of processing units available to the current process. This is useful for parallelizing builds and other workloads. By default, nproc respects cgroup limits, returning the number of CPUs available within containerized environments. This makes it container-aware - a container limited to 4 CPUs will see 4, not the host's full CPU count. The --all option ignores cgroup limits and returns the total number of installed processors. This is useful when you need to know the actual hardware regardless of containerization. Combined with --ignore, you can reserve CPUs for system tasks. For example, `nproc --ignore=1` leaves one core free. Common usage is setting parallel build jobs: `make -j$(nproc)` compiles with one job per available processor. This maximizes build speed while respecting system limits.

How do I run a basic nproc example?

Run `nproc` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --all do in nproc?

Print total number of installed processors, ignoring cgroup limits.