道不远人
ssddyb
全部博文(56)
2010年(39)
2009年(17)
jieisme
zxcvbnm4
HectorZh
lin_1302
D7145636
wangcong
11509285
wwjxjtu
qunzhuqu
分类: LINUX
2010-05-19 13:33:20
#include<stdlib.h> #include<stdio.h> #include<unistd.h> #include<sched.h> int main(int argc, char* argv[]) { int num = sysconf(_SC_NPROCESSORS_CONF); int created_thread = 0; int myid; int i; int j = 0; cpu_set_t mask; cpu_set_t get; if (argc != 2) { printf("usage : ./cpu num\n"); exit(1); } myid = atoi(argv[1]); printf("system has %i processor(s). \n", num); CPU_ZERO(&mask); CPU_SET(myid, &mask); if (sched_setaffinity(0, sizeof(mask), &mask) == -1) { printf("warning: could not set CPU affinity, continuing...\n"); } while (1) { CPU_ZERO(&get); if (sched_getaffinity(0, sizeof(get), &get) == -1) { printf("warning: cound not get cpu affinity, continuing...\n"); } for (i = 0; i < num; i++) { if (CPU_ISSET(i, &get)) { printf("this process %d is running processor : %d\n",getpid(), i); } } } return 0; }
上一篇:linux设置网络访问权限
下一篇:常用linux快捷键
登录 注册