Lab 5 - The Cow Shell
A mini command interpreter
Due: 4:50 PM, Friday, March 19, 2005
For this week's lab, you are to write a C program called the Cow Shell (cowsh), a mini command shell interpreter. cowsh is similar to familiar Unix shells such as the Bourne shell (sh) the Bourne-Again shell (bash), and C shell (csh, tcsh). You will learn about process creation, implementation of pipes, input/output redirection, background processes, signals, interrupt handling, and the use of some system calls.
This lab is considered a "team program" (groups of size 2 or 3 permitted) for honor code purposes. Collaboration within a group is, of course, unrestricted. You may discuss the program with members of other groups, but what you turn in must be your own group's work. Groups must be formed no later than 4:00 PM, Friday, March 12, 2005, and be confirmed by all group members by electronic mail to terescoj@cs.williams.edu. All group members will be assigned the same grade for the lab. There are many subtasks that can be carved off and assigned to group members, so everyone is encouraged to join a group.
Like the familiar Unix shells, cowsh should issue a prompt (perhaps "cowsh#"), at which it reads commands from the user and executes them.
Your shell should interpret the following commands and provide the following functionality:
For example,
cowsh# cat cat.c
should execute cat with one argument, cat.c
For example,
cowsh# cat < cat.c > myfile.cshould cause the cat program to read from cat.c and write to the file myfile.c.
For example,
cowsh# cat cat.c | wc > count.txt
should cause the output of cat cat.c to be the input of wc >
count.txt.
cowsh# sleep 55 & ; invoke sleep in background
cowsh# cat < hello.c ; give other commands
cowsh# ... ; other commands
cowsh# ... ; other commands
[2] "sleep" terminated ; sleep command is done
cowsh# jobs
PID Name
[0] mycat < myfile.c > newfile.c
[1] idle 20
[4] grep cowsh < doc | wc
cowsh# kill
kill <pid> [<pid> ...]
Otherwise it kills the process with the specified ids and displays the process killed.
cowsh# kill 4
[4] "grep" Killed
cowsh# kill 3 7
[3] "cat" Killed
[7] "wc" Killed
Ideas for extra functionality include:
^ modification of previous command
>>, >&, |&
;-separated commands
See builtin(1) for more ideas.
All necessary files should be submitted using turnin as a single "tar" file, lab5.tar. Include a Makefile to allow easy compilation of the Cow Shell program.
I will compile and test your shell programs on CSLab FreeBSD systems.
Your program will be graded based on a total of 40 points.
>>, >&, |&,
user-specified prompts, ;-separated commands.