我使用这段c/c++代码调度2个处理器并行运行2个不同的程序。请问我如何确认两个处理器正在并行运行这两个程序?
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
#include <sched.h>
#include <stdio.h>
#include <cstdlib>
int main(int argc, char *argv[])
{
cpu_set_t mask;
CPU_ZERO(&mask);
int pid;
pid=fork();
if (pid == 0) { /* second child */
CPU_SET(0, &mask);
sched_setaffinity(0, sizeof(mask), &mask);
system("/home/ifeanyi/Process/PID/Debug/PID");
}
else if (pid > 0) { // Parent ends
CPU_SET(1, &mask);
sched_setaffinity(getpid(), sizeof(mask), &mask);
cout << getpid() << endl;
system("/home/ifeanyi/Process/checkpointing/Debug/checkpointing"); // Last leaf
}
cout << endl;
}发布于 2011-12-15 15:31:38
与在你的程序中硬编码这些细节相比,从命令行使用taskset进行编码通常更容易、更灵活。
$ taskset -c 0 ./my_program &
$ taskset -c 1 ./my_program &https://stackoverflow.com/questions/8515861
复制相似问题