Next: About this document ...
Project3: Producer-Consumer (200 points)
This project asks you to use UNIX system calls to solve the
classic problem of coordinating two process, a producer and a consumer.
The producer process produces values (for example prime numbers)
and stores them in a common buffer or in a file that can hold
only one of the values thus produced. The consumer process obtains
the values from the storage location used by the producer and
consumes them (for example, print them).
Producer and consumer work at different rates. To
guarantee their integrity each value produced by producer
must be consumed by the consumer. That is, values produced by producer
should not be lost via overwriting by a speedy producer
interacting with a slow consumer. The consumer should not consume
two times the same value such as when the consumer is faster than the
producer.
- You are required to write a producer/consumer program that consists
of three processes, a parent that forks two children, a producer,
and a consumer. The parent process generates K prime numbers
(K is an argument of the command line of the program) and writes
them on a file called InFile. The producer reads numbers from InFile
and stores them in a common location for the consumer to consume
them. The consumer process consumes the prime numbers by appending
then to a file called OutFile. You need to use the
lock file communication technique to coordinate the activity of
the two processes, producer and consumer (50 points).
- To appreciate the advantages pipes provide for process synchronization
I am asking you to develop a second implementation of the producer-consumer
problem described above where the interaction between producer and
consumer processes is implemented by pipes (50 points).
- Simulate the producer and consumer working at different rates by
using sleep(secs) system call where secs are small random numbers
(50 points).
- When EOF of the InFile is detected the producer terminates by storing
in the common location -1. When -1 is detected by the consumer it
terminates as well. The parent continues and proves that the coordination
between producer and consumer was correctly implemented by comparing the
two file, InFile and OutFile. If the two files are identical then the
coordination between producer and consumer was correctly implemented and
the parent sends a message to the program user telling this. If the InFile is different from
the OutFile the parent sends a message to the program user telling that coordination between
producer and consumer was incorrectly implemented (50 points).
Due date is Wednesday 1 October 2003
Documents to be handed in:
- A complete specification of the problem you solve
- C-language algorithm solving the problem
- User manual of the two programs you implemented.
The user manual should contain the information:
- Your account number
- Where is the source code
- Compilation procedure
- Executable code and testing experiments
- Procedure for prime number generation
Next: About this document ...
Teodor Rus
2003-09-23