Links: [Course Home] [Schedule] [Learning Objectives] [Resources] [Moodle]
Due Wednesday, March 22 at 10:00 AM. There is an automatic grace period of 24 hours associated with this deadline. This is the only consideration that will be given for minor emergencies.
You may work in groups of up to three students. Please have just one group member submit the assignment (see instructions below).
As a reminder, the course collaboration policy will be strictly enforced on this assignment.
For this project, you are to write a simple shell-like program in C that reads user commands and executes them using a combination of "fork", "exec", and "pipe".
Your shell should be able to handle commands of the following types. I recommend developing your code in this order, but it's not required:
ps -u yourusernameYour shell should fork a new process to exec each of these commands.
who | wc -lYour shell should fork twice, once to create a process to run "who" and the second time to run "wc" (with option "-l"). You should use a pipe for the two children to communicate. That is, the process that runs "who" will read from stdin and write to your pipe, and the process that runs "wc" will read from that pipe and write to its standard output.
ls /usr/bin | head -10 | tail -5This prints the 6th through the 10th commands from the list of commands in /usr/bin. Your shell will need to create three processes and link them together using two pipes. The first child process runs "ls" and writes its output to a pipe. The second child process runs "head" (with argument "-10"), with its input coming from the first process's pipe, and its output going to a second pipe. The third child process, which runs "tail", will read from that second pipe and write its output to stdout.
wc -l < inputfile
who > outputfile
wc -l < inputfile > outputfile
tr "A-Z" "a-z" < wcExample.cpp | tr -cs "a-z" '\012' | sort | uniq -c | sort -nr | head -1This series of commands finds the most common word in "wcExample.cpp" and prints it along with the number of times that it has been repeated. Note that you will have to strip the quotes from the arguments that are quoted before passing them to exec.
To get started, copy the files in ~srivoire/cs450/pickup/hw2 to your directory on the CS department server (blue.cs.sonoma.edu). You should have the following files, which you can use as a basis for your code:
Processing simple commands with no redirection | 5 points |
Processing commands with one pipe | 10 points |
Processing commands with two pipes | 10 points |
Processing commands with an arbitrary number of pipes | 20 points |
Processing simple commands with input and/or output redirection | 20 points |
Processing commands combining pipes and input and/or output redirection | 20 points |
Error handling (see "Basics") | 5 points |
Design and style (see below) | 10 points |
Total for assignment | 100 points |
---|
Design and style will be assessed on the following criteria:
In addition to your source files, your submission should include a makefile and a file named groupmembers.txt listing your group members (unless you worked by yourself).
Run "make clean" before submitting. Then, back up to your parent directory and run
tar czvf hw2.tgz yourdirectory
Submit your tarfile on Moodle.