/* ELEC 377, Lab 3 * * master.c * Contains the main() function which fork()s all the worker processes (do_convolution()) and then * waits for the answers to come back. */ #include #include #include #include #include #include #include #include "common.h" #define FALSE 0 #define TRUE 1 #define MYPID 1 int main (int argc, char *argv[]){ // initialize the shared memory, load in the initial array's, spawn the worker // processes. key_t key; struct shared *memptr; int shmid; int c,stored; /* Shared memory init */ key = ftok(".", 'S'); if((shmid = shmget(key, MEMSIZE, IPC_CREAT|0666)) == -1 ){ if( (shmid = shmget(key, MEMSIZE, 0)) == -1){ printf("Error allocating shared memory. \n"); exit(1); } } // now map the region.. if((int)(memptr = (struct shared *) shmat(shmid, 0, 0)) == -1){ printf("Couldn't map the memory into our process space.\n"); exit(1); } mutexInit(memptr); // put your code here.. return 0; }