[Reprint] Linux process to determine which method CPU core running

Linux process method to determine which CPU core running

Original URL: http://www.embeddedlinux.org.cn/html/xinshourumen/201601/30-5013.html

Question: Is there a Linux process running on multi-core processor system, to see how the process is run on which CPU?

method one:

If a process using taskset clear command is fixed (Pinned) to a specific core CPU, you can use the command to find out taskset fixed CPU core:

taskset -c -p <pid>

For example, if you are interested in 5357 for the process of PID, you can use the following command to view its run on which CPU:

taskset -c -p 5357

Operating results: pid 5357's current affinity list: 5, output displays the process is fixed to the No. 5 CPU. However, if you do not explicitly fixed the process to any CPU, you will get a list of similar affinity for the following:

pid 5357's current affinity list: 0-11, the output indicates that the process may be arranged on from 0-11 to any one CPU. In this case, taskset not recognize the process which is currently assigned to the CPU, you should use the following method.

Method Two:

ps command can tell you (the "PSR" column) CPU ID for each process / thread is currently assigned to.

ps -o pid,psr,comm -p <pid>

operation result:

PID PSR COMM

5357  10  prog

Output represents the PID of the process to 5357 (known as "prog") currently running on a number of the CPU 10. If the process is not fixed, PSR row kernel may change to a different schedule of the process according to the display CPU.

Method three:

The top command can also display the CPU is assigned to which process. First, use the "P" option in the top command. Then, press the "F" key, the display will be "Last used CPU" column appears. Currently used by the CPU will appear in "P" (or "PSR") under a column.

Proceed as follows:

1、top -p 3393

2, pressing the "F" key

3, using the arrow keys to select P = Last Used Cpu, and pressing the space key, a "*" to

4, press the "Q" key

Compared to the ps command, the benefits of using top command is: you can continuously monitor changes over time, CPU is the distribution.

Method four:

Another to check a process / thread CPU which is currently used method is to use htop command.

Htop started from the command line. Press the "F2" key to enter the "Columns", added under the "Available Columns" PROCESSOR, press "F10" to save, CPU ID for each process currently in use will appear in the CPU column.

Please note that all commands previously used taskset, ps and top IDs assigned CPU core is 0,1,2, ..., N-1. However, htop IDs assigned CPU core 1 from the start (up to N).

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/11349893.html