Project Overview Introduction ------------ The operating systems project is to write concurrent programs on a Unix system, using semaphores and shared memory. The implementation of semaphores and shared memory is provided. In order to write concurrent programs, you would write each process as a Unix process (or program that is executed separately). Each program will have access to the SAME semaphores and shared memory as all the other programs that comprise your concurrent program. The programs and test programs are in the directory: ~partha/CSE430 They consist of the following files: os.h : A header file. Must be included with all programs. template.c : A template, useful for guidelines on how to write a process. sem1.c, sem2.c : Sample semaphore programs. mem1.c, mem2.c : sample programs using shared memory. semtest.c : same as sem1.c and sem2.c, but written as 1 program with 2 processes in it. Getting Started --------------- To use the concurrent programming features, you must: 1] Include a file in all the programs: #include "os.h" 2] Initialize the concurrent programming support: In your main program, the first line should be: Initialize(); Execution of this routine will produce an output of the form: Initialized 8388608 100 ^^ this number must be positive, if not there is a problem with the system, try your program again or later. Using 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. 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 os.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. More information: ----------------- The os.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 os.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.