Finding processor id in which process is running [through command/interface similar to top]

风流意气都作罢 提交于 2019-12-07 18:09:21

问题


Is there any way i can get the CPU which CPU the process is running?


回答1:


You can use /proc/[id]/stat file and read the 39th value (seperated by spaces). This tells which cpu id the process of [pid] is currently running on:

cat /proc/[id]/stat | awk '{print $39}'

For more info: man proc.




回答2:


If you wanna get it in code, it is the variable current points to.




回答3:


You can use "ps" command as:

You can use "ps" command as:

ps -p <pid> -o pid,comm,psr
Ex:
ps -p 1 -o pid,comm,psr
PID COMMAND         PSR
1   init              10


来源:https://stackoverflow.com/questions/8131320/finding-processor-id-in-which-process-is-running-through-command-interface-simi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!