Pipes

Due: 11:00pm, Thursday, October 5, 2023

Get the Assignment Code

Login to your university Unix account and copy the assignment code to a location under your home directory:

  cp -r /export/home/public/schwesin/csc328/assignments/project4 LOCATION

where LOCATION is a directory of your choosing.

Description

For this project you will write a program that utilizes pipes to allow a parent and child process to communicate. You can use any programming language that allows the creation of new processes similar to the fork() system call in C and the use of pipes similar to the pipe() system call in C.

Parent Process

The parent process will generate a random number between 0 and 100 (not including 0 or 100), using the parent process’s PID as the seed. The parent will send this random number to the child, followed by a second message containing the product of the random number and the child process’s PID. The parent will then wait for a response from the child. After receiving a response from the child, the parent will check the child’s message. If it is “Approved”, the parent will print “Thanks for playing”. If the message received from the child is “Denied”, the parent will print “Wrong. Please play again”. The parent will then send another message to the child telling the child it is okay to end. This message should be “BYE”. The parent will end after all child processes have ended.

Child Process

The child process will wait to receive the random number from the parent, followed by the second number. The child will confirm the second number is correct. If it is correct, the child will send the message “Approved” to the parent. If the number is not correct, the child will send the message “Denied” to the parent. The child will then wait for another message (BYE) from the parent indicating it is okay for the child to end. The child process will then end.

Both Processes

Both processes should print to standard output the message it will write to the pipe and any message it receives from the pipe. Each message printed must include the process (“Parent” or “Child”) and if the message will be sent to the pipe or if it was received by the pipe.

Example Output

Parent sending to pipe: 47
Child received from pipe: 47
Parent sending to pipe: 784392
Child received from pipe: 784392
Child sending to pipe: Approved
Parent received from pipe: Approved
Parent: Thanks for playing!
Parent sending to pipe: BYE
Child received from pipe: BYE

Makefile Rules

The following rules must be added to the provided Makefile:

Turning in the Assignment

To turn in the assignment, execute the submit script by running the command

  make submit

from within the project4 directory.

Grading Criteria