设置与 C++ 的处理器关联性将在 Linux 上运行
可能的重复:
CPU 亲和力
我在 Linux 上运行,我想编写一个 C++ 程序来设置我的 2 个特定处理器2 个并行运行的应用程序(即将每个进程设置为在不同的核心/CPU 上运行)。我想将处理器关联工具与 C++ 一起使用。请任何人帮忙编写 C++ 代码。
Possible Duplicate:
CPU Affinity
I'm running on Linux and I want to write a C++ program that will set 2 specific processors that my 2 applications that will run in parallel (i.e. setting each process to run on a different core/CPU). I want to use processor affinity tool with C++. Please can anyone help with C++ code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在命令行中,您可以使用 taskset(1),或者在代码中您可以使用 sched_setaffinity(2)。
例如
From the command line you can use taskset(1), or from within your code you can use sched_setaffinity(2).
E.g.
您需要调用 sched_setaffinity 或 pthread_setaffinity_np
另请参阅此问题
You need to call sched_setaffinity or pthread_setaffinity_np
See also this question