EECS 371 - MP 4: Communication using UNIX Pipes

Due: Tuesday April 3, 2001 at 11:59 pm

This assignment will have you create a single consumer process that receives information from multiple producer processes via a single UNIX pipe. The single consumer must be a child of the initial/parent process. The producer processes will also be child processes of the initial/parent process.

The parent process will need to get information from the command line, create the pipe for communication, create the proper number of child processes, and wait() for all child processes to complete. The command line will have two pieces of information.

  1. The number of producer processes.
  2. The number of items each producer is to create.
Both values must be integers. If the command line does not contain exactly two integer values, an error message is to be given and the program terminated. There can be from 1 to 26 producer processes. If the first integer value is outside of this range, an error message is to be given and the program terminated. The number of items each producer creates must be a value greater than zero. If the second integer value is not greater than zero, an error message is to be given and the program terminated.

Each producer process will create and write to the pipe N number of single letters, where N is the second value from the command line. Each write operation is to write exactly one letter. The first child process will create and write the letter "A", the second child process will create and write the letter "B", the third child process will create and write the letter "C", etc. When the producer process has created and written N letters, it is to make sure both ends of the pipe it has are closed and to exit() the process.

The consumer process is to close its write end of the pipe. The consumer process will then read letters from the pipe and print them out to standard output in some uniform way (i.e. 75 letters per line). As each letter is read from the pipe, the consumer process is to keep track of the number of each letter is read from the pipe. Each read operator is to read exactly one letter. The consumer process is to keep reading from the pipe until the pipe is empty and no other process can write to the pipe (the read command will return a special value when this condition has been met). After all information is read from the pipe, the consumer must check if any letters were lost on the pipe. An appropriate message must be written to state whether any letter were lost.

It is suggested that you write the program in steps. First have the program only create one producer. Then have the program create two producers. Finally have the program create N producers. 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 familar with the ps and kill -9 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 mp4 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 mp4 <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.