#include using namespace std; const int size = 4; //For 4 elements per vector int list[size]; float flist[size]; int shareid[4]; extern "C"{ //link c functions from util.o int process_fork(int nproc); void process_join(int nproc,int pid); int *shareint (int size, int& mid); void clean_up_shared(int id); } int main() { //declare main variables int i,j, id ; float *q, *p, *sum2, *sum1, total; p = (float*) shareint (size * sizeof (int),shareid[0]); //share variables q = (float*)shareint (size * sizeof (float),shareid[1]); sum1 = (float*) shareint (sizeof (*sum1),shareid[2]); sum2 = (float*)shareint (sizeof (*sum1),shareid[3]); for (j =0; j < size; j++){ //input integer data cout << " p[" << j << "] = "; cin >> p[j]; } for (j =0; j < size; j++){ //input real data cout << " q[" << j << "] = "; cin >> q[j]; } id = process_fork(2); if (id==0) for (i=0; i< size; i++) *sum1 +=p[i]; else for (i=0; i< size; i++) *sum2 +=q[i]; process_join(2,id); total=(*sum1)+ (*sum2); cout << "The sum of the array P is " << *sum1 << endl; cout << "The sum of the array q is " << *sum2 << endl; for (i=0; i<4; i++) clean_up_shared (shareid[i]); return (0); }