CSC 442 Homework 2

Write a program that implements the producer-consumer problem using a pipe. The parent will read from the keyboard one line at a time (max 80 characters) and write it into the pipe. The child will read from the pipe and display the content on the screen. This will continue until the user types the character '$' when both processes will display a message ("Good bye") and will exit.


The program will create a pipe and then fork. The child will close the write end of the pipe, the parent will close the read end of the pipe.

The program should use the following system calls:

  1. pipe -creates a pipe.
  2. fork - create a new process.
  3. read - reads a number of bytes from a file specified by a file descriptor.
  4. write - writes a number of bytes to a file specified by a file descriptor.
  5. open - opens a file.
  6. close - closes a file.
  7. exit - terminates a process.

You may use whatever else you think is necessary (printf, scanf, etc.).

You will need to include the following files: stdio.h, unistd.h, stdlib.h, string.h.



  1. A print-out of your program.
  2. A written description of the program and its behavior.
  3. The source code of the program. The source code should be contained in a folder (directory) called "homework2" in your home directory. The permissions of this folder and all the files included should be such that I can open the files, compile them and run the program.