- How to Run Process or Program on Specific CPU Cores in Linux
- Install taskset
- Install taskset on Ubuntu and Debian system
- Install taskset on CentOS,RHEL and Fedora system
- Know the CPU affinity of a running process
- Assign Running Process To Particular CPU Cores
- Run a Program on Specific CPU cores
- Dedicate a Whole CPU core to a Particular Program
- Update GRUB Configuration File to Dedicate a Whole CPU Core to a Particular Program
- 9 Commands to Check CPU Information on Linux
- CPU hardware information
- 1. /proc/cpuinfo
- 2. lscpu — display information about the CPU architecture
- 3. hardinfo
- 4. lshw
- 5. nproc
- 6. dmidecode
- 7. cpuid
- 8. inxi
- 9. Hwinfo
- Conclusion
- 15 thoughts on “ 9 Commands to Check CPU Information on Linux ”
- How Do I Find Out Linux CPU Utilization?
- The old good top command to find out Linux CPU Utilization
- Top command to find out Linux cpu usage
- Say hello to htop
- Find Linux CPU utilization using mpstat and other tools
- Display the utilization of each CPU individually using mpstat
- Report CPU utilization using the sar command
- Comparison of CPU utilization
- Task: Find out who is monopolizing or eating the CPUs
- iostat command
- vmstat command
- How to interpret vmstat CPU section output
- turbostat command
- nmon command
- GUI tools for your laptops/desktops
- Conclusion
How to Run Process or Program on Specific CPU Cores in Linux
Multi-core CPUs becoming popular these days on server-grade hardware and end-user desktop PCs, Laptops. Suppose we have a multi-core processor, whenever we run a program (process) it may be execute using all the available cores or if it does not need more CPU usage then single core is more capable to handle it. But still while executing, it may be switch between the multiple CPU cores by Operating System. It is almost best for letting the Operating System to handle process. But smart user have the ability to make a certain process to execute by only using a single CPU core. It has a slight benefit in server performance. Because in a multi-core CPU environment all individual CPUs have separate cache for each CPU core which is only accessible by that CPU ( CPU cache know as L1, L2, and L3)
In this tutorial I am going to describe how we can run a process or program on specific CPU cores in Linux.
To run a process or program on specific CPU cores you, you can use taskset. It is a command line tool for setting a process CPU affinity in Linux.
Install taskset
Taskset tools is part of util-linux package in Linux, and it comes with pre-installed in most Linux distros by default. If it is not available by default on your Linux machine you can install it using below command.
Install taskset on Ubuntu and Debian system
Run the below command to install taskset package on Ubuntu and Debian system.
Install taskset on CentOS,RHEL and Fedora system
Know the CPU affinity of a running process
Follow the below command to know the CPU affinity of a process with process ID of 5850.
In above example, the affinity corresponds to “11111111” in binary format. It means the process can run on any eight cores ( from 0 to 7 ).
Instead of a bitmask, tasktest can show CPU affinity as a list of processors which is easy to read. Run the below command with -c option to use this.
Assign Running Process To Particular CPU Cores
Follow the below command to pin a running process to particular CPU cores.
For example, assign a process to CPU core 0 and 4.
Run a Program on Specific CPU cores
You can also launch a new program as assign to specific CPU cores with taskset.
For example, launch google-chrome on CPU core 0.
Dedicate a Whole CPU core to a Particular Program
Using taskset we can assign particular program to certain CPUs, It does’t mean that no other process or programs will be scheduled on those CPUs. We can use “isolcpus” kernel parameter to dedicate a whole CPU core to a particular program. Using kernel parameter we can reserve the CPU core during boot.
Update GRUB Configuration File to Dedicate a Whole CPU Core to a Particular Program
You will need to update the grub configuration file to dedicate a whole CPU cores to particular program. Then Linux scheduler will not schedule any other regular process on the reserved CPU cores. Update grub configuration file with below content.
cpuidle.off=1 :- Do not make cpu idle
isolcpus=0,1 :- Core 0 and 1 are isolate (reserved)
maxcpus=6 :- Use only 6 cores out of 8 cores of system
idle=poll :- Poll forces a polling idle loop
I hope this article will help to to run process or program on specific CPU cores in Linux. Read our another articles Googler – Command Line Google Search On Linux System and Top 5 Web Based Linux Monitoring Tools. If you have any queries and problem please comment in comment section or you can also ask your question.
Источник
9 Commands to Check CPU Information on Linux
CPU hardware information
The cpu information includes details about the processor, like the architecture, vendor name, model, number of cores, speed of each core etc.
There are quite a few commands on linux to get those details about the cpu.
In this post we shall take a look at some of the commonly used commands that can be used to get details about the cpu.
1. /proc/cpuinfo
The /proc/cpuinfo file contains details about individual cpu cores.
Output its contents with less or cat.
Every processor or core is listed separately the various details about speed, cache size and model name are included in the description.
To count the number of processing units use grep with wc
To get the actual number of cores, check the core id for unique values
So there are 4 different core ids. This indicates that there are 4 actual cores.
2. lscpu — display information about the CPU architecture
lscpu is a small and quick command that does not need any options. It would simply print the cpu hardware details in a user-friendly format.
3. hardinfo
Hardinfo is a gtk based gui tool that generates reports about various hardware components. But it can also run from the command line only if there is no gui display available.
It would produce a large report about many hardware parts, by reading files from the /proc directory. The cpu information is towards the beginning of the report. The report can also be written to a text file.
Hardinfo also performs a few benchmark tests taking a few minutes before the report is displayed.
4. lshw
The lshw command can display limited information about the cpu. lshw by default shows information about various hardware parts, and the ‘-class’ option can be used to pickup information about a specific hardware part.
The vendor, model and speed of the processor are being shown correctly. However it is not possible to deduce the number of cores on the processor from the above output.
5. nproc
The nproc command just prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.
6. dmidecode
The dmidecode command displays some information about the cpu, which includes the socket type, vendor name and various flags.
7. cpuid
The cpuid command fetches CPUID information about Intel and AMD x86 processors.
The program can be installed with apt on ubuntu
And here is sample output
8. inxi
Inxi is a script that uses other programs to generate a well structured easy to read report about various hardware components on the system. Check out the full tutorial on inxi.
Print out cpu/processor related information
To learn more about the inxi command and its usage check out this post:
Inxi is an amazing tool to check hardware information on Linux
9. Hwinfo
The hwinfo command is a hardware information program that can be used to collect details about various hardware components on a Linux system.
It also displays information about the processor. Here is a quick example:
If you don’t use the «—short» option it will display much more information about each cpu core like architecture and processor features.
To learn more about the hwinfo command check this post:
Check hardware information on Linux with hwinfo command
Conclusion
Those were some of the commands to check CPU information on Linux based systems like Ubuntu, Fedora, Debian, CentOS etc.
For some more command examples on checking cpu information check this post:
How to Check Processor and CPU Details on Linux — Command Examples
Most of the commands are command line based and show text output. For a GUI interface use the program called Hardinfo.
It shows hardware details about various components in a easy to use GUI interface.
If you know of any other useful command that can display information about the CPU, let us know in the comments below.
A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .
15 thoughts on “ 9 Commands to Check CPU Information on Linux ”
Very nicely explained. I highly recommend it in my articles. thank you.
Thank you for the information, i learn lot in this article. 🙂
Thanks for the Information.
Hi everybody, someone know how to get same information regarding the hardware where I installed a phisical linux ?
Thank you for sharing, it helping lot.
lshw now (DISTRIB_DESCRIPTION=”Linux Mint 17.3 Rosa”) includes a line like below at the bottom of it’s listing:
configuration: cores=4 enabledcores=4 threads=8
How to get the number of real cores, not HiperThreading.
For example, for i7, real cores are 4, but logical are 8. There is some way without root ?
check this post for commands to check the number of real cores.
https://www.binarytides.com/linux-check-processor/
are we still catting into grep?
grep ‘core id’ /proc/cpuinfo
yo Silver Moon, nice write-up bro. absolutelly useful stuff there, though the number of CPUs can be fetched using just ‘grep -c processor /proc/cpuinfo’. take care 🙂
Thank you for the helpful information. You can not look for “unique values” with the “cat /proc/cpuinfo |grep ‘core id’” command on a multiprocessor system. The situation gets even worse with hyperthreading enabled CPU’s.
Источник
How Do I Find Out Linux CPU Utilization?
W henever a Linux system CPU is occupied by a process, it is unavailable for processing other requests. Rest of pending requests must wait until the CPU is free. This becomes a bottleneck in the system. Following command will help you to identify CPU utilization, so that you can troubleshoot CPU-related performance problems on a Linux-based system. This page explains how to check Linux CPU utilization and usage using various tools.
Finding CPU utilization is one of the important tasks. Linux comes with various utilities to report CPU utilization. With these commands, you will be able to find out:
- CPU utilization
- Display the utilization of each CPU individually (SMP cpu)
- Find out your system’s average CPU utilization since the last system reboot
- Determine which process is eating the CPU(s)
The old good top command to find out Linux CPU Utilization
The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The top command monitors CPU utilization, process statistics, and memory utilization. The top section contains information related to overall system status – uptime, load average, process counts, CPU status, and utilization statistics for both memory and swap space.
Top command to find out Linux cpu usage
Type the top command:
$ top
Say hello to htop
htop is similar to top command but allows you to scroll vertically and horizontally and much more.
htop
Find Linux CPU utilization using mpstat and other tools
Please note that you need to install a special package called sysstat to take advantage of following commands. This package includes system performance tools for Linux (Red Hat Linux / RHEL includes these tools by default). Install it on a Debian or Ubuntu Linux using apt-get command/apt command:
# apt-get install sysstat
Use up2date command if you are using RHEL/CentOS Linux v4.x or older:
# up2date install sysstat
Run yum command command if you are using a CentOS/RHEL/Oracle Linux v5.x+ or newer:
# yum install sysstat
Fedora users should run the dnf command:
# dnf install sysstat
Display the utilization of each CPU individually using mpstat
If you are using SMP (Multiple CPU) system, use mpstat command to display the utilization of each CPU individually. It report processors related statistics. For example, type command:
# mpstat
Sample outputs:
The mpstat command display activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed.:
# mpstat -P ALL
Sample outputs:
Another output from my Ubuntu 18.04 LTS server:
Report CPU utilization using the sar command
You can display today’s CPU activity, with the help of sar command:
# sar
Output:
Comparison of CPU utilization
The sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system, based on the values in the count and interval parameters. For example display comparison of CPU utilization; 2 seconds apart; 5 times, use:
# sar -u 2 5
Output (for each 2 seconds. 5 lines are displayed):
- -u 12 5 : Report CPU utilization. The following values are displayed:
- %user: Percentage of CPU utilization that occurred while executing at the user level (application).
- %nice: Percentage of CPU utilization that occurred while executing at the user level with nice priority.
- %system: Percentage of CPU utilization that occurred while executing at the system level (kernel).
- %iowait: Percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
- %idle: Percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
To get multiple samples and multiple reports set an output file for the sar command. Run the sar command as a background process using.
# sar -o output.file 12 8 >/dev/null 2>&1 &
Better use nohup command so that you can logout and check back report later on:
# nohup sar -o output.file 12 8 >/dev/null 2>&1 &
All data is captured in binary form and saved to a file (data.file). The data can then be selectively displayed ith the sar command using the -f option.
# sar -f data.file
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Task: Find out who is monopolizing or eating the CPUs
Finally, you need to determine which process is monopolizing or eating the CPUs. Following command will displays the top 10 CPU users on the Linux system.
# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
OR
# ps -eo pcpu,pid,user,args | sort -r -k1 | less
Sample outputs:
Now you know vmware-vmx process is eating up lots of CPU power. The ps command command displays every process ( -e ) with a user-defined format ( -o pcpu ). First field is pcpu (cpu utilization). It is sorted in reverse order to display top 10 CPU eating process.
iostat command
You can also use iostat command which report Central Processing Unit (CPU) statistics and input/output statistics for devices and partitions. It can be use to find out your system’s average CPU utilization since the last reboot.
# iostat Output:
You may want to use following command, which gives you three outputs every 5 seconds (as previous command gives information since the last reboot): $ iostat -xtc 5 3
vmstat command
The vmstat command shows information about processes, memory, paging, block IO, traps, disks and cpu activity. Run vmstat as follows:
vmstat
vmstat [options] vmstat [interval] [count]
Sample outputs:
In this example, run vmstat with an interval of one second twenty one times:
vmstat 1 21
How to interpret vmstat CPU section output
These are percentages of total CPU time.
- us : Time spent running non-kernel code. (user time, including nice time)
- sy : Time spent running kernel code. (system time)
- id : Time spent idle.
- wa : Time spent waiting for IO.
- st : Time stolen from a virtual machine.
turbostat command
The turbostat command shows processor topology, frequency, idle power-state statistics, temperature and power on X86 processors. Simply run as follows:
sudo turbostat
sudo turbostat 5
See turbostat man page for further details.
nmon command
nmon is a systems administrator tool to get information about cpu, top process, memory and much more. One can install it as follows:
sudo apt install nmon ## Debain/ubuntu ##
sudo dnf install nmon ## fedora ##
sudo yum install nmon ## centos/rhel ##
Now start it:
nmon
GUI tools for your laptops/desktops
Above tools/commands are quite useful on remote server. For local system with X GUI installed you can try out gnome-system-monitor. It allows you to view and control the processes running on your system. You can access detailed memory maps, send signals, and terminate the processes.
$ gnome-system-monitor
Sample outputs:
In addition, the gnome-system-monitor provides an overall view of the resource usage on your system, including memory and CPU allocation:
Finding out Linux CPU usage using GUI tool
Conclusion
This page explained various Linux command line tools that we can use to find Linux CPU utilization. For further information, see the following resources:
Источник