// Server code which contains a name/email pairs and will fulfill // requests from a client through FIFOs. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define NRECS 21 #define STRSIZE 128 #define SHM_SIZE (NRECS * sizeof(lookup_t)) // structure to store a lookup_t of name-to-email association typedef struct { char name [STRSIZE]; char email[STRSIZE]; } lookup_t; lookup_t original_data[NRECS] = { {"Chris Kauffman" ,"kauffman@umn.edu"}, {"Christopher Jonathan" ,"jonat003@umn.edu"}, {"Amy Larson" ,"larson@cs.umn.edu"}, {"Chris Dovolis" ,"dovolis@cs.umn.edu"}, {"Dan Knights" ,"knights@cs.umn.edu"}, {"George Karypis" ,"karypis@cs.umn.edu"}, {"Steven Jensen" ,"sjensen@cs.umn.edu"}, {"Daniel Keefe" ,"dfk@umn.edu"}, {"Michael W. Whalen" ,"whalen@cs.umn.edu"}, {"Catherine Qi Zhao" ,"qzhao@umn.edu"}, {"Dan Challou" ,"challou@cs.umn.edu"}, {"Steven Wu" ,"zsw@umn.edu"}, {"Michael Steinbach" ,"steinbac@cs.umn.edu"}, {"Jon Weissman" ,"jon@cs.umn.edu"}, {"Victoria Interrante" ,"interran@cs.umn.edu"}, {"Shana Watters" ,"watt0087@umn.edu"}, {"James Parker" ,"jparker@cs.umn.edu"}, {"James Moen" ,"moen0017@cs.umn.edu"}, {"Daniel Giesel" ,"giese138@umn.edu"}, {"Jon Read" ,"readx028@umn.edu"}, {"Sara Stokowski" ,"stoko004@umn.edu"}, }; int main(int argc, char *argv[]) { if(argc < 2){ printf("usage: %s restore\n",argv[0]); printf(" %s lookup \n",argv[0]); printf(" %s change \n",argv[0]); exit(1); } key_t key = ftok("shmdemo.c", 'R'); // make the SysV IPC key int shmid = shmget(key, SHM_SIZE, 0644 | IPC_CREAT); // connect to (and possibly create) the segment: lookup_t *data = (lookup_t *) shmat(shmid, (void *)0, 0); // attach to the segment to get a pointer to it: if( strcmp("restore",argv[1])==0 ){ printf("Restoring\n"); for(int i=0; i