Basic Instructions for dealing with IPC primitives for the project The following are some resources for use in message passing, semaphores and shared memory. For this assignment, your program should be in 1 file (1 file for client, 1 file for server). 531.h is a header file, that you include in your program template.c has some code that may help you. There are routines in 531.h that provide: 1] Message Passing: sendport(int port, char *mesg, int size): send a message of size from *mesg to port. receiveport(int port, char *mesg, int maxsize): Receive a mesg from port The ports are constant numbers (see template.c). 2] Semaphores: Three routines are provided. They are InitSem(S), P(S), and V(S). To use them, first define the semaphores. Each semaphore is a constant integer (or number). If you need 3 semaphores called S1, S2 and S3: #define S1 1 #define S2 2 #define S3 3 Now you can use the 3 routines on these semaphores. Note, this definition MUST be present in all the programs that use S1, S2 and S3. You are encouraged to put the semaphore definitions in a header file and including the header file in all the programs. Note that a sempahore MUST be initialized before it is used. 3] Using Shared Variables: ALL regular C variables defined in your programs will be private (regardless whether they are global or declared in a function). The 531.h file, upon initialization will provide you with a shared segment (or array) of 1024 words, pointed to by a pointer called SHMEM. Thus to define some shared variables, use the following scheme: #define v2 SHMEM[1] #define v3 SHMEM[2] #define v4 SHMEM[3] You can also define a shared array, look at the template.c file for details. 4] Initialization To use the features described above, you must: 1] Include the 531.h file in all the programs: #include "531.h" 2] Initialize the concurrent programming support: In your main program, the first line should be: Initialize(n); Execution of this routine will produce an output of the form: Initialized 8388608 100 5] More information: The 531.h file uses the Initialize routine to attach a message queue (used to implement semaphores) and a shared memory segment to your program. The "id" of these are based on your user id, hence all your programs get the same message queue and shared memory. In addition to the features defined above, the 531.h file provides: rndon(i): A random number generator that returns a number between 0 and i-1. StartProcess(proc): A routine that starts a process, running the procedure proc. 6] Silly Semaphore Tricks Here are some programs that work and show how to use semaphores and shared memory sem1.c, sem2.c semtest1.c, mem1.c, mem2.c: You may need a cleanup program. Here is the code for it.