CPU亲和 [英] CPU Affinity

查看:199
本文介绍了CPU亲和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有设置CPU的亲和力在C / C ++为Linux操作系统。

Is there a progamatic method to set CPU affinity for a process in c/c++ for the linux operating system.

推荐答案

您需要使用了sched_setaffinity(2)man 页)

例如,在CPU 0和2只运行:

For example, to run on CPUs 0 and 2 only:

#include <sched.h>

cpu_set_t  mask;
CPU_ZERO(&mask);
CPU_SET(0, &mask);
CPU_SET(2, &mask);
result = sched_setaffinity(0, sizeof(mask), &mask);

0 第一个参数是指当前进程,提供一个PID,如果是要控制一些其他进程)。

(0 for the first parameter means the current process, supply a PID if it's some other process you want to control).

这篇关于CPU亲和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆