当前位置: 动力学知识库 > 问答 > 编程问答 >

executing two program in differet processors in parallel

问题描述:

I used this c/c++ code to schedule 2 processors to run 2 different programs in parallel. please how do I confirm that the 2 processors are running the 2 programs in parallel?

#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;

}

网友答案:

Rather than hard-coding these details in your program it is in general easier and more flexible to do it from the command line using taskset, e.g.

$ taskset -c 0 ./my_program &
$ taskset -c 1 ./my_program &
分享给朋友:
您可能感兴趣的文章:
随机阅读: