栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何知道我的代码在哪个物理处理器和哪个物理内核上运行

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何知道我的代码在哪个物理处理器和哪个物理内核上运行

您可以根据http://www.kernel.org/doc/documentation/filesystems/proc.txt检查/
proc // stat文件系统,只需检查task_cpu标志。

没有正确类型和错误检查的示例:

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;//      number of major faults with child's  int utime;//         user mode jiffies  int stime;//         kernel mode jiffies  int cutime;//        user mode jiffies with child's  int cstime;//        kernel mode jiffies with child's  int priority;//      priority level  int nice;//          nice level  int num_threads;//   number of threads  int it_real_value;//  (obsolete, always 0)  int start_time;//    time the process started after system boot  int vsize;//         virtual memory size  int rss;//resident set memory size  int rsslim;//        current limit in bytes on the rss  int start_pre;//    address above which program text can run  int end_pre;//      address below which program text can run  int start_stack;//   address of the start of the stack  int esp;//current value of ESP  int eip;//current value of EIP  int pending;//       bitmap of pending signals  int blocked;//       bitmap of blocked signals  int sigign;//        bitmap of ignored signals  int sigcatch;//      bitmap of catched signals  int wchan;//         address where process went to sleep  int i0;//  (place holder)  int i1;//  (place holder)  int exit_signal;//   signal to send to parent thread on exit  int task_cpu;//      which CPU the task is scheduled on  int rt_priority;//   realtime priority  int policy;//        scheduling policy (man sched_setscheduler)  int blkio_ticks;//   time spent waiting for block IO  int gtime;//         guest time of the task in jiffies  int cgtime;//        guest time of the task children in jiffies} p ;int main(){    char name[256];    char state[8];    FILE* f = fopen("/proc/self/stat", "r");    fscanf(f,  "%d%s%s%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",&p.pid, &p.tcomm, &p.state, &p.ppid, &p.pgrp, &p.sid, &p.tty_nr, &p.tty_pgrp, &p.flags,&p.min_flt, &p.cmin_flt, &p.maj_flt, &p.cmaj_flt, &p.utime, &p.stime,  &p.cutime, &p.cstime,&p.priority, &p.nice, &p.num_threads, &p.it_real_value, &p.start_time,  &p.vsize, &p.rss,&p.rsslim, &p.start_pre, &p.end_pre, &p.start_stack, &p.esp, &p.eip,  &p.pending, &p.blocked,&p.sigign, &p.sigcatch, &p.wchan, &p.i0, &p.i1, &p.exit_signal,  &p.task_cpu, &p.rt_priority, &p.policy,&p.blkio_ticks, &p.gtime, &p.cgtime);     printf("CPU %dn", p.task_cpu); return 0;   }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403076.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号