Starting from:

$29.99

COP4600 Assignment 1- Process API in Unix Solution



Learning Objectives
The objective of this assignment is to experiment with process API in Unix and to better understand how the Unix shell works by trying to mimic its behavior.
Problem 1
Write a C program that does the following:
• Creates a new process (using fork());
• Makes the new process execute cmd with params as parameters, if given.
• Waits for the new process to finish executing, and then prints ++++ on a new line.
Problem 2
This problem builds significantly on the previous problem. Specifically, it asks you to again use fork() to create processes and exec() (or one of the many variants) to assign the newly created processes what to do. In addition, however, it asks you to mimic the behavior of a shell command such as:
ls | wc
What happens in the case above is the output of the first command (’ls’) becomes the input to the second command (’wc’). (Try it in a terminal on a Unix machine). Thus, you are required to write another program that:
• Expects an input of the form: cmd1 | cmd2
• Creates two processes
• Makes the first process run cmd1
• Makes the second process run cmd2
• Makes sure that the output of the first process becomes the input of the second process (using the function pipe()).
• Waits for the two processes to finish before it ends by printing ++++ on a new line.
1

What to Submit
Name your C files as problem1.c and problem2.c and place them in a folder called assignment1. Compress the folder into a .tar file:
tar -cvf assignment1.tar assignment1
This will download the tar file to the location this command was run from. Submit the tar file on Canvas.
Other Instructions and Suggestions
• The C functions (that, in fact, use system calls) you’ll need include: fork(), wait(), pipe(), exec() (or variants). You might want to also experiment with and use for debugging the functions getpid() and getppid().
• For on-line reference manuals use the command man as below:
man -s 2 pipe
man man man getppid man -s 2 exec

More products