Linux Command to Find Processor Number for a Process

cpucpu usagelinuxprocess

Is there any command in Linux to figure out, given a process, which processor the process is running? I am interested in figuring out the CPU busy and CPU idle time of that processor.

Best Answer

You can use the ps command to query and display the active processor. For example, you might run:

$ ps -aF
UID        PID  PPID  C    SZ   RSS PSR STIME TTY          TIME CMD
root         1     0  0  5971  1764   1 Sep15 ?        00:00:01 /sbin/init
ubuntu   28903  2975  0  3826  1208   0 09:36 pts/0    00:00:00 ps -aF

The PSR column shows that init is running on processor 1 and ps is running on processor 0. See the manpage for ps(1) for more details on how to customize the fields that are displayed.

You can configure a graphical tool like htop to display the current active processor. Also, htop has a per-CPU load display graph, which may be what you're looking for. See, for example, the following screenshot from http://htop.sourceforge.net/.

htop screenshot

Finally, you can use the taskset tool to force affinity to a particular CPU.

Related Question