相关函数:
sched_setaffinity, sched_getaffinity, CPU_CLR, CPU_ISSET, CPU_SET, CPU_ZERO - set and get a process's CPU affinity mask
#define _GNU_SOURCE
#include <sched.h>
int sched_setaffinity(pid_t pid, unsigned int cpusetsize,
cpu_set_t *mask);
int sched_getaffinity(pid_t pid, unsigned int cpusetsize,
cpu_set_t *mask);
void CPU_CLR(int cpu, cpu_set_t *set);
int CPU_ISSET(int cpu, cpu_set_t *set);
void CPU_SET(int cpu, cpu_set_t *set);
void CPU_ZERO(cpu_set_t *set);
#include <sched.h>
int sched_setaffinity(pid_t pid, unsigned int cpusetsize,
cpu_set_t *mask);
int sched_getaffinity(pid_t pid, unsigned int cpusetsize,
cpu_set_t *mask);
void CPU_CLR(int cpu, cpu_set_t *set);
int CPU_ISSET(int cpu, cpu_set_t *set);
void CPU_SET(int cpu, cpu_set_t *set);
void CPU_ZERO(cpu_set_t *set);
CPU_ZERO(&mask);
CPU_SET(cpu_id, &mask);
sched_setaffinity(pid, sizeof(mask), &mask);
本文转自eyjian 51CTO博客,原文链接:http://blog.51cto.com/mooon/908714,如需转载请自行联系原作者