查看Linux 下绑定进程到 CPU的源代码
←
Linux 下绑定进程到 CPU
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== GLibc API == <source lang=cpp> #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); </source> Example: <source lang=cpp> unsigned int cpu_mask; unsigned int pid = 1; unsigned int mask = 0x1; // 绑定到 CPU0,0x2 则绑定到 CPU1 if (sched_getaffinity (pid, 4, &mask) < 0) fprintf (stderr, "failed to get cpu affinity: %s\n", strerror (errno)); else { printf ("setting cpu affinity of pid=%d to %x\n", pid, cpu_mask); if (sched_setaffinity (pid, 4, &cpu_mask) < 0) fprintf (stderr, "failed to get cpu affinity: %s\n", strerror (errno)); else if (sched_getaffinity (pid, 4, &mask) < 0) fprintf (stderr, "failed to get cpu affinity: %s\n", strerror (errno)); else printf ("cpu affinity of pid=%d is %x\n", pid, mask); } </source> Other macros to manipulate the bitset (set, reset bits): <source lang=cpp> 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); </source> Reference: * http://www.gnu.org/software/libc/manual/html_node/CPU-Affinity.html <br>
返回到
Linux 下绑定进程到 CPU
。
个人工具
3.144.116.188
该IP地址的讨论
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面