Chinaunix首页 | 论坛 | 博客
  • 博客访问: 216607
  • 博文数量: 88
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 555
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-03 13:08
个人简介

失意高调,得意低调

文章分类

全部博文(88)

文章存档

2021年(3)

2020年(2)

2018年(2)

2017年(3)

2016年(6)

2015年(19)

2014年(32)

2013年(21)

我的朋友

分类: LINUX

2016-12-23 13:42:30

#define _GNU_SOURCE
#include


cpu_set_t mask;
cpu_set_t get;
int j;


int num = sysconf(_SC_NPROCESSORS_CONF);
printf("system has %d processor(s)\n", num);

CPU_ZERO(&mask);
CPU_SET(1, &mask);
if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
printf("set thread affinity failed\n");
}

CPU_ZERO(&get);
if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
printf("get thread affinity failed\n");
}
for (j = 0; j < num; j++) {
if (CPU_ISSET(j, &get)) {
printf("thread %d is running in processor %d\n", (int)pthread_self(), j);
}
}

阅读(902) | 评论(0) | 转发(0) |
0

上一篇:Linux设备驱动之USB hub驱动(续)

下一篇:没有了

给主人留下些什么吧!~~