linux - 在处理器的特定核心上运行进程

标签 linux operating-system multiprocessing

<分区>

Possible Duplicate:
CPU Affinity

在运行 Linux (fc12) 的 x86 机器上,我可以让一个进程在多处理器系统的特定内核上运行吗?我知道有一个函数 sched_setaffinity 可以帮助选择处理器,但我想在处理器的特定核心上执行该过程。

最佳答案

不确定这是否是您需要的,我使用这段代码使线程在特定核心上运行。 使用 -pthread 编译和链接。

#include "pthread.h"
#include "sched.h"

int affinity = 3; //core id
pthread_t mythread;
mythread = pthread_self();
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(affinity, &cpuset); //lets kernel know only core affinity may run this thread
if (pthread_setaffinity_np(mythread, sizeof(cpu_set_t), &cpuset) <0){
    perror("sched_set_affinity");
}

关于linux - 在处理器的特定核心上运行进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12197222/

相关文章:

python - Python 中的多处理具有大量进程但限制 cpu 数量

python-3.x - 在进程池python中排序

linux - 为 linux 编写鼠标手势应用程序的语言?

linux - 如何保护我的进程不被杀死?

linux - awk脚本中的命令行输入?

c++ - C++中的类成员变量可以定义多种数据类型吗?

c - 在 C 中链接文件/头文件

c++ - 为什么基本引用没有堆开销?

linux - 为什么现代操作系统需要这么多内存?

c - 系统如何知道没有更多未等待的 child