前言
最近大家都在积极的写博客呀,咸鱼也不能落下。
正文
需要注意的是, 下面的两种方法,我们获得的都是逻辑core的编号。
比如我的CPU是四核八线程,通过/proc/cpuinfo
,就能看到8个core,编号0-7.而我们查看的话,也就是看位于core的编号是啥。。。
外部方法
主要通过ps
命令来进行观察,
$ ps -o psr -p <pid>
程序中查看
在程序中通过sched_getcpu()
可以查看当前进程当前所运行在哪个cpu,如果想要查看别的进程可以通过/proc/<pid>/stat
查看
查看的方式就有点粗暴了。
下面引用自stackoverflow
struct pstat
{
int pid; //process id
char tcomm[256];//filename of the executable
char state[2]; //state (R is running, S is sleeping, D is sleeping in an
//uninterruptible wait, Z is zombie, T is traced or stopped)
int ppid;// process id of the parent process
int pgrp;// pgrp of the process
int sid;// session id
int tty_nr;// tty the process uses
int tty_pgrp;// pgrp of the tty
int flags;// task flags
int min_flt;// number of minor faults
int cmin_flt;// number of minor faults with child's
int maj_flt;// number of major faults
int cmaj_flt;