Getting started with Linux: How do I know which CPU kernel the process runs on?

Source: Internet
Author: User

Getting started with Linux: How do I know which CPU kernel the process runs on?

Problem: I have a Linux Process running on a multi-core processor system. How can I find out which CPU kernel is running this process?

When you run a high-performance HPC (high-performance computing) program or a program that consumes a lot of network resources on a multi-core NUMA processor, CPU/memory affinity is one of the important factors to maximize its performance. Scheduling the most relevant processes on the same NUMA node can reduce slow remote memory access. Like the Intel Sandy Bridge processor, This processor has an integrated PCIe controller that allows you to schedule network I/O loads (such as NICS) on the same NUMA node to break the PCI-to-CPU affinity limit.

As part of performance optimization and troubleshooting, you may want to know which CPU kernel (or NUMA node) the specific process is scheduled to run.

There are several ways to find out which CPU kernel is scheduled to run a specified Linux Process or thread.

 

Method 1

If a process uses the taskset command to explicitly pin it to a specific CPU kernel, you can use the taskset command to find the fixed CPU kernel:

  1. $ taskset -c -p <pid>

For example, if you are interested in the PID 5357 process:

  1. $ taskset -c -p 5357
    Pid 5357's current affinity list: 5

The output shows that the process is fixed on CPU kernel 5.

However, if you do not specify a fixed process to any CPU kernel, you will get an affinity list similar to the following.

  1. pid 5357's current affinity list: 0-11

The output indicates that the process may be scheduled to any CPU kernel from 0 to 11. In this case, taskset cannot identify the CPU kernel that the process is currently allocated to. You should use the method described below.

 

Method 2

The ps command tells you the cpu id currently allocated by each process/thread (in the "SRS" column.

  1. $ ps-o pid,psr,comm -p <pid>
    PID PSR COMMAND
    535710 prog

The output indicates that the PID of the process is 5357 (named "prog") and is currently running on CPU kernel 10. If the process has not been fixed, the PSR column will change the display according to the kernel which may schedule the process to different kernels.

 

Method 3

The top command can also display the process to which the CPU is allocated. First, use the "P" option in the top command. Press the "f" key to display the "Last used CPU" column. The currently used CPU kernel will appear in the "P" (or "SRS") column.

  1. $ top-p 5357

Compared with ps commands, the advantage of using top commands is that you can continuously monitor how the CPU is allocated as time changes.

 

Method 4

Another way to check which CPU kernel is currently used by a process/thread is to use the htop command.

Start htop from the command line. Press the key to enter "Columns". PROCESSOR is added under "Available Columns.

The cpu id currently used by each process appears in the "CPU" column.

Please note that all previously used commands taskset, ps and top are allocated to the CPU kernel IDs as 0, 1, 2,..., N-1. However, htop allocates CPU kernel IDs starting from 1 (until N ).

Via: http://ask.xmodulo.com/cpu-core-process-is-running.html

Author: Dan Nanni Translator: strugglingyouth Proofreader: wxy

This article was originally compiled by LCTT and launched with the honor of Linux in China

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.