I am currently working on a project about setting process to one core in linux environment. I use sched_setaffinity to do this job and I wonder whether there are some functions provided by linux to get which core the process is running on. I use top command and find it could get this info using j option. So i am sure there are some ways to get this info in user space.
Share
You probably want
sched_getcpu(). If you are running an older version of glibc, you can read the 39th field of/proc/[pid]/statfor the appropriate pid — see theproc(5)man page for more details.