Programming Assignment 3
CS 51520
Operating Systems
Fall, 2021
This assignment makes use of the files contained in this zip file.
This assignment is due Monday, November 29.
This assignment is based on the examples from the zip file child-to-child-pipeline.zip.
You will write a Linux C program, called hw3.c
, that implements a three stage pipeline.
The hw3.c
program should take exactly three command-line arguments which are the names of Linux executable programs.
If the command-line for hw3
looks like this,
$ ./hw3 prog1 prog2 prog3
then the hw3.c
program should build a three stage pipeline as shown in the following picture.
hw3
+----------+
| |
+--------------------->> 0 1 >>----------------------------------+
| | | |
| | 2 >>-------------------------------+ |
| | | | |
---+ +----------+ | +-->
| | |
| | |
| prog1 prog2 prog3 | |
| +----------+ +----------+ +----------+ | |
| | | pipe | | pipe | | | |
+-->> 0 1 >>-0======0->> 0 1 >>-0======0->> 0 1 >>-----+
| | | | | | |
| 2 >>--+ | 2 >>--+ | 2 >>--+-->
| | | | | | | | |
+----------+ | +----------+ | +----------+ |
| | |
+-----------------------+-----------------------+
The hw3
process should wait on the process prog3
and when prog3
terminates,
hw3
should print a brief message to stdout and then terminate.
In the zip file there is a folder called "filters
" that contains a number of simple filter programs that all read from stdin
and write to stdout
. They make good candidates for the programs in the filter stages. So, for example, you could test your version of hw3.c
with a command-line like this.
$ ./hw3 filters/double filters/remove_vowels filters/twiddle
Be sure to test your version of hw3.c
with a command-line like this one.
$ ./hw3 filters/double filters/remove_vowels filters/twiddle < hw3.html > temp.txt
That will run hw3.c
with hw3
's stdin
redirected to the file hw3.html
and with hw3
's stdout
redirected to the file temp.txt
. If your hw3.c
is written correctly, this command-line should put those two files on the ends of the pipeline and you should see the result of the pipeline stored in the file temp.txt
Your hw3
process should print a brief error message and terminate if there are not exactly three command-line arguments. Your hw3.c
program should error check all Linux function calls (like pipe
, dup
, fork
, exec
).
There are many ways that you can organize the code in your hw3.c
program (just as we had several ways of organizing the code for creating a two-stage pipeline in the examples from child-to-child-pipeline.zip). Create a document that explains the sequence of steps that your code takes to create the three-stage pipeline. The code that you end up writing in hw3.c
will probably not be too easy to read. So your explanation document should clearly explain the steps your code takes. (Hint: A well written explanation will do a lot to help you write and debug your code.)
If you use Windows Subsystem for Linux, the Window's Task Manager may not help you much with seeing the Linux processes that your hw3.c
program creates. The Linux commands pstree, ps, and top and be used in WSL to see the parent-child relationships of your Linux processes. In particular, try using top's V
"interactive command", which shows a tree view of your processes.
Turn in a zip file called CS51520Hw3Surname.zip
(where Surname
is your last name) containing your version of hw3.c
and your explanation document.
This assignment is due Monday, November 29.