CIS 361 Project 2: Simple Shell
Deliverables: The source code to your shell, turned in via blackboard. If your code consists of multiple files, please also include a makefile. Additionally, you will also be required to demo you program for the instructor on the due date.
Grading: 100 points, as described below.
Groups: This project may be done individually or in groups of two. If working in a group, you must additionally turn in a short document describing the main contributions of each group member.
In this assignment, you are to write a simple unix shell, similar to BASH, although with considerably fewer features. Your shell must be written in C, and must comiple and run on the EOS linux systems. Specific requirements include:
- (20 points) Your shell should prompt a user for input. When provided with input, in most cases it must be interpreted as a command to run a program, which you must do via fork and exec (any function in the exec family is fine).
- (10 points) Both absolute and relative path names for programs must be supported. If a program name is provided without a path at all, you should use the PATH environment variable inherited from the environment your shell was run from to find the appropriate executable program.
- (5 points) Appropriate errors should be printed if a program is not found.
- (5 points) Additional arguments on the command line must be passed to the program being run though exec.
- (25 points) Some commands must be implemented as shell builtins (your shell should not run a program to do these, instead they should be done directly by the shell itself). These commands are:
- pwd - print the current directory
- cd - change directory
- history - show command history
- exit - exit the shell
- jobs - print list of jobs currently running in the background
- (5 points) Your shell should maintain a command history. You do not need to be able to scroll through it or search it like in bash. It must be possible to view commands in the history and their command number using the "history" bultin. It must be possible to run a command from history by typing ! followed by the command number.
- (10 points) You must support redirection of standard output and standard input of commands run from your shell via the > and < operators.
- (5 points) You must support running programs in the background if an & is at the end of the command line. If the & is not present, the process should be run in the foreground. While in reality there are a few more differences, for this project, a shell should immediately prompt for and handle more commands after running a background process, but for a foreground process the shell should wait until the foreground process is finished.
- (5 points) You must set your shell to not exit on Ctrl-c or stop on Ctrl-z. Instead, it must simply print that a Ctrl-c or Ctrl-z was seen.
- (10 points) Your shell must catch the SIGCHLD signal when a child process exits. In this case, it must call wait or waitpid to clean up the child process record. The return status code from the child should be printed if the exiting process was a foreground process. Be careful here to avoid race conditions.