Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see which CPU core a thread is running in?

In Linux, supposing a thread's pid is [pid], from the directory /proc/[pid] we can get many useful information. For example, these proc files, /proc/[pid]/status,/proc/[pid]/stat and /proc/[pid]/schedstat are all useful. But how can I get the CPU core number that a thread is running in? If a thread is in sleep state, how can I know which core it will run after it is scheduled again?

BTW, is there a way to dump the process(thread) list of running and sleeping tasks for each CPU core?

like image 889
flypen Avatar asked Nov 07 '11 03:11

flypen


People also ask

How do I know which core my thread is running on?

First, launch top command with p option. Then press f key, and add Last used CPU column to the display. The currently used CPU core will appear under P (or PSR ) column.

Does thread run on different core?

In short: yes, a thread can run on different cores.


1 Answers

The "top" command may help towards this, it does not have CPU-grouped list of threads but rather you can see the list of threads (probably for a single process) and which CPU cores the threads are running on by

top -H -p {PROC_ID}

then pressing f to go into field selection, j to enable the CPU core column, and Enter to display.

like image 146
maltanar Avatar answered Sep 19 '22 16:09

maltanar