Homework 2: Exceptional Flows
The programming part
For this assignment you are to write a simple program that will act as a shell. The program shall
- Display a command prompt and read in a command line from the user
- Parse the command line into arguments, creating an array of character pointers, where array[0] points to the actual command and rest of the array elements point to the arguments to the command (Similar to main()’s argv[])
- Fork of a child and have the child load the requested program by passing the argument vector created in step 2 to exec() family of system calls. The parent should report the PID of the child before proceeding to the next step.
- Wait for the child to complete executing and report why it ended (exited or uncaugt signal) and its exit value if available.
- Repeat for first step forever till user enters the command
exit
- Your shell should also support basic I/O redirection line the unix shell.
$ command > filename
Redirects the output of command to filename. The existing contents of filename are overwritten.$ command >> filename
` Redirects the output of command to filename. The output from command is appendend to contents of filename. Existing contents are not overwritten.$ command < filename
Command reads its input from filename instead of from stdin.
- Your shell should handle the following signals:
- SIGINT - Generated by Ctrl-C. This signal allows a user to teminate a running program. Your shell should not exit when user presses Ctrl-C but simply report that SIGINT signal has been received by the shell.
- SIGTSTP - Generated by Ctrl-Z. Your shell should not exit when user presses Ctrl-Z but simply report that SIGTSTP signal has been received by the shell.
- The shell need not support background processes or running more than one child at a time.
git, class repositories (repos)
You should have cloned the public repository for the previous homework. To update your copy of the public repository
$ cd public $ git pull
your personal repository
Note that there is no skeleton code for the homework. Going to lab sections is highly advisable, as the TA has been and will be explaining basics of getting started with a shell. Both the lab section code, as well as code found in the book or book slides, are “fair game” from which to begin your coding. Previous solutions, or other students’ work, are off limits and any cheating will be prosecuted to the fullest extent of university rules.
Template
There is no skeleton code for this assignment. WHen you turn in the assignment, the TA should be able to compile your program by running make
in the hw2
directory. You are responsible for creating that makefile - ask us if you have questions about how to do so.
Turn-in instructions
Remember, if you don’t push, we don’t see it! We will be making copies of the repositories at each deadline (full credit, 10% off, etc), so do not leave this for the last minute. If you submit it one second too late, you’ll be in the next lateness bracket, no exceptions.
To make sure your submission is complete, try the following in a temporary directory, i.e. create and change into a temporary directory under the /tmp
filesystem:
mkdir /tmp/hw2-temp cd /tmp/hw2-temp git clone git@git.uicbits.net:cs361-s15/MYUSERNAME.git cd MYUSERNAME git checkout hw2 cd hw2 make ./hw2
If at that point you can use the shell to run the commands above properly, you’ve done everything correctly.
Grading
Grading will be done automatically using a script.
Due Date
This assignment is due Friday, February 13, at 8 AM. See the syllabus for the late turnin policy. This assignment is worth just as much as every other homework, and they will only get harder from here, so getting as much credit on it as possible is important (don’t turn it in late!).