get_nprocs - Linux


get_nprocs is a command-line utility that retrieves the number of online processors (CPU cores) on the current system. It provides a quick way to get the number of available CPU cores, which can be useful for various tasks such as optimizing system resources, performance analysis, and task distribution.


get_nprocs [OPTIONS]


  • -h, –help: Display usage information and exit.
  • -v, –version: Print version information and exit.


  • Get the number of CPU cores:
$ get_nprocs
  • Check if the system has at least 4 CPU cores:
$ if [ $(get_nprocs) -ge 4 ]; then echo OK; fi
  • Use with other commands:
$ taskset -c 0-$(($(get_nprocs) - 1)) my_program  # Distribute a task across all CPU cores

Common Issues

  • Incorrect output: Make sure to run the command as the root user for accurate results.
  • Not found: Ensure that the get_nprocs command is installed and available in your PATH.


  • Combine with other commands: Use get_nprocs with commands like taskset or numactl to optimize task scheduling and memory usage.
  • Scripting: Integrate get_nprocs into scripts to automate performance analysis or resource optimization tasks.

Related Commands

  • nproc: Similar to get_nprocs, but typically includes virtual cores.
  • lscpu: Provides detailed information about the CPU, including core count.
  • htop: A graphical tool to monitor CPU usage and core distribution.