Starting from:

$29.99

CS3305A Assignment 2 Solution



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 process. The parent process will read the first command-line argument into variable X while the child process will read second and third command-line argument into variable Y and Z, respectively. The parent process will write X to the pipe and wait for the child process to finish. The child process will read X from the pipe written by the parent process. After that, the child process concatenates Y and Z to generate Y' and then concatenates X and Y' to generate Z'. The child process will write Z' into the pipe (i.e., shared memory). The parent process will read Z' from the pipe and output the resulting string. The expected output from your program should look like the following for the arguments "CS","3305", and "is fun!":

1. parent (PID 2209) created a child (PID 2213)
2. parent (PID 2209) receives X = "CS" from the user
3. parent (PID 2209) writes X = "CS" to the pipe
4. child (PID 2213) receives Y = "3305" and Z = "is fun!" from the user
5. child (PID 2213) concatenates Y and Z to generate Y' = " 3305 is fun!"
6. child (PID 2213) reads X from pipe = "CS"
7. child (PID 2213) concatenates X and Y' to generate Z' = "CS 3305 is fun!"
8. child (PID 2213) writes Z' into the pipe
9. parent (PID 2209) reads concatenated result from the pipe (Z' = "CS 3305 is fun!")



Hints: fork(), wait(), pipe(), write(), read()

1

Mark Distribution


• Inter-Processes Communications (100 points)
a) Parent reads X from user: 10 points
b) Child reads Y & Z from user: 12 points
c) A pipe is created for communication between parent and child: 20 points
d) Parent writes X into the pipe: 12 points
e) Child reads X from the pipe: 12 points
f) Child writes Z' into the pipe: 12 points
g) Parent reads Z' from the pipe: 12 points
h) Output the correct string: 10 point

Computing Platform for Assignments



• 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



2

More products