How can I find out in which core the process is running?

I am currently working on a project to configure a process for a single kernel in a linux environment. I use sched_setaffinity to accomplish this task, and I wonder if there are any functions provided by linux to get the kernel that runs this process. I use the top command and I believe that she can get this information using the j option. Therefore, I am sure that there are some ways to get this information in user space.

+4
source share
2 answers

You probably want sched_getcpu() . If you are using an older version of glibc, you can read the 39th field /proc/[pid]/stat for the corresponding pid - see the proc(5) page for more details.

+5
source

To achieve this, you can use the built-in assembly (on x86 architecture):

 mov eax, 1 ; cpuid functionality depends on the value of eax cpuid ; get cpu info shr ebx, 24 ; ebx[31:24] is the cpu ID. mov eax, ebx ; eax contains the cpu ID 

You can learn more about the CPUID instruction here http://download.intel.com/design/processor/applnots/24161832.pdf

+1
source

All Articles