OBJECTIVES

To develop a C program that uses fork(), pipe(), and the exec family of process system calls to implement a producer/consumer communication.

PROBLEM

You are to use the Ubuntu operating system to create a C program named execTwo.c. Your execTwo.c program will use modified versions of your producer.c and consumer.c programs you developed for lab 4. The requirements for the new versions of both producer.c and consumer.c are provided as follows.

The consumer.c program will read integers from stdin and will write to stdout only the even numbers found in the input provided. The producer.c program will write 20 integers to stdout. Both programs, the producer and the consumer, will communicate by means of reading and writing to shared pipes. Your solution must execute both producer and consumer programs by means of a single command. You may use the fork(), pipe(), dup(), dup2(), read(), write(), creat(), as well as any of the exec() family of system calls.

Assume after your .c files are compiled and named execTwo, producer, and consumer. Also assume the input set contains integers from 0 to 19. The command that follows must be used to obtain the even numbers from the input set displayed at stdout.

Prompt> ./execTwo producer consumer
Prompt> 0 2 4 … 16 18
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.