1 Overview

This project focus on creating a simple shell, the ”Wimpy SHell”, which will use a command line interface, and will support foreground (interactive) processing, background (batch) processing, redirection, pipes, and job control.

1.1 System calls

1.2 Foreground Jobs

A ”foreground job” is a command of the form ARG0ARG1ARGn , and a foreground process is created with following procedures:

  1. Create a new process using fork
  2. Replace the image of the created process with the desired command using one of execl(), execlp(), execle(), execv(), execvp(), execve().
  3. Wait for the process to terminate using waitpid().

For examples:
cp file1 file2
cp -R dir1 dir2
rm -f -R dir1 dir2 file1 file2
xterm

1.3 Background jobs

A background job, a command of the form ARG0ARG1ARGn&, acts like a foreground job, except the shell does not wait for the process to terminate, but let the process run at the background. Thus, a background job should be executed as follows:

  1. Create a new process using fork
  2. In the newly created process, replace its image with the desired command using one of execl(), execlp(), execle(), execv(), execvp(), execve().

Unlike foreground jobs, the shell must keep track of background job information using an appropriate data structure. This allows the shell to display the status of each background job. Each background job should be assigned a ”job number”, to be used as an index when displaying the information about the job. A background job’s number should remain fixed for its life. The job numbers should be incremented for each new background job, and when no background jobs exist, the job number should reset to 1. For example:
Running:
[1] cp file1 file2
[2] cp -R dir1 dir2
[4] xterm
Finished:
[3] rm -f -R dir1 dir2 file1 file2
If the xterm is then closed, the next status report might be:
Running:
[1] cp file1 file2
[2] cp -R dir1 dir2
Finished:
[4] xterm

1.4 Redirection for standard I/O

Both background and foreground jobs should be able to redirect standard input and output using < and >, respectively, where > outputs to the designated file, and < reads data from the specified file. For example, ls -a -l -F > file1
ls -a -l -F > file2 &
should send the output of ls to file1 and file2,
cat -n < file1
should read from file1 instead of standard input, and
cat < file1 > file2
cat > file3 < file1
should read from file1 and write to file2 and file3.

1.5 Support of build-in commands

Here is the list of build-in command:

  1. cd (newdir): change the current working directory to ”newdir”, and display it.
  2. wait (job): wait for specified background job (with job id #) to terminate
  3. exit: word tells it all, to exit the shell.

1.6 Pipes

A command pipeline of the form job1|job2||jobn , where each job is a sequence of arguments (like a foreground job). Examples:
cat -n file | less
ls -alF | sort -n -r +4 | head -5
cat -n file1.cc file2.cc | grep #include | sed -e s/include/exclude/ | head -5
yes + | head -15 | cat -n | sed s/10/10x/ | tr -d \ n | tr x \ n | head -1 | bc