Description
Purpose
The goals of this assignment are the following:
• Get experience with the fork(), wait() and pipe() system functions.
• Learn how to use pipe for bi-directional communication between parent and child process.
• Gain more experience with the C programming language from an OS perspective.
Inter-Processes Communications (100 points)
Write a C program that will accept three strings from the user as command-line arguments (for
example, X, Y, and Z). Your parent process will create a child. While the parent waits for the
message to be available in the pipe, the child will access X (“CS”) and write it in the pipe. Then
the parent will read the message from the pipe and access Y (“3305”). Now parent will concatenate
the read message and Y (“CS 3305”), and write it in the pipe. This time child will read the message
from the pipe and access Z (“is Fun!”). Then the child will concatenate the read message and Z
(“CS 3305 is Fun!”), and write it in the pipe. Now the child will be completed, and the parent will
read the message from the pipe. The expected output from your program should look like the
following for the arguments “CS”, “3305”, and “is fun!”:
parent (PID 1458): created child (PID 1459)
child (PID 1459): received X = “CS”
child (PID 1459): writing “CS” into pipe
parent (PID 1458): read from pipe “CS”
parent (PID 1458): received Y = “3305”
parent (PID 1458): “CS” + Y = “CS 3305”
parent (PID 1458): writing into pipe “CS 3305”
child (PID 1459): read from pipe “CS 3305”
child (PID 1459): received Z = “is Fun!”
child (PID 1459): “CS 3305” + Z = “CS 3305 is Fun!”
child (PID 1459): writing into pipe “CS 3305 is Fun!”
child (PID 1459): all tasks completed
parent (PID 1458): read from pipe “CS 3305 is Fun!”
parent (PID 1458): all tasks completed
Hints: fork(), wait(), pipe(), write(), read()
2
Mark Distribution
This section describes a tentative allocation of marks assigned for the desired features.
• Inter-Processes Communications (100 points)
a) Child reads X & Z from Command Line: 10 points
b) Parent reads Y from Command Line: 12 points
c) A pipe is created for communication between parent and child: 20 points
d) Child writes X into the pipe: 12 points
e) Parent reads X from the pipe: 12 points
f) Parent concatenates message and Y before writing into the pipe: 12 points
g) Child concatenates message and Z before writing into the pipe: 12 points
h) Output the correct string: 10 point
NOTE: Marks will be deducted if error handling is not implemented in your code.
Computing Platform for Assignments
You are responsible for ensuring that your program compiles and runs without error on the
computing platform mentioned below. Marks will be deducted if your program fails to compile,
or your program runs into errors on the specified computing platform (see below).
• Students have virtual access to the MC 244 lab, which contains 30 Fedora 28 systems. Linux
machines available to you are: linux01.gaul.csd.uwo.ca through linux30.gaul.csd.uwo.ca.
• It is your responsibility to ensure that your code compiles and runs on the above systems. You
can SSH into MC 244 machines (please see the Assignment 1 file transfer tutorial).
• If you are off campus, you have to SSH to compute.gaul.csd.uwo.ca first (this server is also
known as sylvia.gaul.csd.uwo.ca, in honour of Dr. Sylvia Osborn), and then to one of the MC
244 systems (linux01.gaul.csd.uwo.ca through linux30.gaul.csd.uwo.ca) (please see the
Assignment 1 file transfer tutorial).
• https://wiki.sci.uwo.ca/sts/computer-science/gaul
Assignment Submission
You need to submit only one C file. The name of your submitted C file must be “assignment2.c”.
Marks will be deducted if your submitted C file name is different. You must submit your
assignment through OWL. Be sure to test your code on one of MC 244 systems (see “Computing
Platform for Assignments” section above). Marks will be deducted if your program fails to
compile, or your program runs into errors on the computing platform mentioned above.
Assignment 2 FAQ will be made available on OWL, as needed. Also, consult TAs, and the
Instructor for any questions you may have regarding this assignment.