如何查看进程运行在哪个CPU上

前言

最近大家都在积极的写博客呀,咸鱼也不能落下。

正文

需要注意的是, 下面的两种方法,我们获得的都是逻辑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;
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值