This assignment will simulate the readers and writers (reader priority) problem using UNIX System V IPC Semaphores and Shared Memory. Be sure to look at the code given in chapter six of Silbershatz and Galvin to help you with this assignment. There will be 5 memory elements (stored in shared memory) that the code can either read or write. Each memory element can have multiple reads occurring simultaneously, but each write operation must occur mutually exclusive of any other read or write operation. Writing to one of the these memory elements must not effect the reading or writing to any of the other four memory elements. That is, your program must be able to write to different memory elements simultaneously.
For the assignment, you will need to have your program accept command line arguments. The command line arguments will be a list of file names. The number of files names given will specify the number of processes that will be executing the readers and writers problem. Each file name will contain a sequence of commands that will control how a process will read and write the shared memory. Each line will only contain a single command. The first non-white-space character on the line will be the command character. The command characters can be in either upper or lower case. The commands are as follows:
The r command is to cause the process to read from the <num>-th shared memory element. The value of <num> must be an integer value from 1 to 5. A value outside out that range should result in an error message and the command should be ignored.
The w command is to cause the process to write the value <val> to the <num>-th shared memory element. The value of <num> must be an integer value from 1 to 5. A value outside out that range should result in an error message and the command should be ignored. The value of <val> must be an integer value. A non-integer value should result in an error message and the command should be ignored.
The s command is to cause the process to sleep for <val> seconds. The value of <val> must be a positive integer value. A non-integer value or a non-positive integer should result in an error message and the command should be ignored.
Each child/reader-writer process will begin by opening the proper file to read commands from. If the file does not open properly, print out some error message and exit that child process. After the file has been opened, the process will process the commands given in the file. If a command is unknown print out an error message and ignore that line in the file. The process is to continue processing commands until the end of the file is reached. The following are some sample data files:
Both the read and write commands have there own entry sections, critical sections and exit sections (refer to the Silbershatz and Galvin text for the descriptions of these three sections). Immediately prior to executing the code for the entry section, print out a message that will list:
It is suggested that you write the program in steps. First have the program only create one reader-writer process. Then have the program create two reader-writer process. Finally have the program create N reader-writer process (where N is the number of filenames given on the command line). This should help reduce the possibility of creating a program that runs out of control and produces more children than can be allowed on the system; effectively crashing the system. Avoiding this with keep you from being the target of the wrath of EECS computer support. I also suggest that you become familiar with the following UNIX commands:
The assignment is expected to be the result of individual work. You will submit the project electronically using the UNIX turnin command with the project name of mp5 as shown below, where <files> is a list of all files that you wish to submit. Refer to the man page on the system for more information about the turnin command.
$> turnin -c eecs371 -p mp5 <files>All of your programs must be written in a good programming style. This is to include in-line comments, a file header, function headers, blank lines, indentation, meaningful variable names, readable output, etc. The first two lines of your file must comments stating how you compiled your program on the EECS department's UNIX machines and how you ran your program. You must also submit a makefile with your program that will properly compile your program.