0
我用這個c/C++代碼來安排2個處理器並行運行2個不同的程序。請如何確認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;
}
你至少應該從了sched_setaffinity檢查結果代碼 - 它返回0或-1:http://linux.die.net/man/2/sched_setaffinity – 2011-12-15 06:57:15