Understanding the hardware configuration of the Linux system is fundamental for optimizing its performance and ensuring efficient resource allocation. One crucial aspect of this understanding is determining the number of CPU cores and threads available, as they directly influence the system's ability to handle tasks concurrently. This tutorial shows how to check number of CPU cores and threads on Linux.
Execute the following command to obtain the number of CPU cores:
awk -F': ' '/cpu cores/{print $2;exit}' /proc/cpuinfo
To fetch the count of threads (logical processors), utilize the provided command:
grep -c ^processor /proc/cpuinfo
Output example of both commands:
24
32
Here's a breakdown of the first command:
awk
- is a command line tool for text processing.-F': '
- specifies the field separator as a colon followed by a space./cpu cores/
- it instructsawk
to search for lines containingcpu cores
.{print $2;exit}
- prints the second field (after the colon and space), representing the number of CPU cores. Theexit
statement ensures thatawk
exits after processing the first occurrence ofcpu cores
.
Here's a breakdown of the second command:
grep
- is a command line tool for pattern matching.-c
- this option instructsgrep
to count the number of lines that match the pattern.^processor
- this is the pattern to match. In this context,^
is a special character in regex that anchors the pattern to the start of a line, andprocessor
is the literal string we're matching.
Leave a Comment
Cancel reply