UMBC CSEE Computer Science & Electrical Engineering
University of Maryland Baltimore County
Baltimore Maryland 21250 USA
voice: 410-455-3500 fax: -3969
UMBC| CSEE| CSEE users| CSEE help

Project 1: Implementing a Simple Shell

(c) 1997, Howard E. Motteler; Modified by Gary L. Burt, 1998, 1999

Assigned: 2 June; Due:28 Oct

Project Goals The goals of this project are to learn the basics of how a "shell" or command interpreter works, and to gain experience programming with UNIX processes and system calls.

The Project

You are to design and implement a simple shell, "mysh". Some of the commands of this shell are to be internal and some are to external. The internal commands for project will be the command to list the directory (the UNIX "ls" command), the change directory command (cd) and the "exit" command).

The following is a prototype of what your main might look like:

while ( TRUE )					/* repeat forever           */
{
    read_command( command, parameters);	/* read input from terminal */

    if ( fork( ) != 0 )				/* fork off child process   */
    {
	  /* Parent Code */
	  waitpid( -1, &status, 0 )		/* wait for child to exit   */
    }
    else
    {
	  /* Child code */
        execve( command, parameters, 0 ); /* execute the command	    */
    }
}

Specifications

Your shell should be able to parse and execute command lines of the following form

cmd
cmd > file
cmd < file
cmd < file > file
cmd | cmd
cmd ; cmd
!!
!nr

where:

Grading

Make sure you have read the general information on programming projects. Approximately 20% of your grade is for documentation, and the remainder is based on how well your project works. You should describe your design and implementation at the beginning of the project; this initial description is worth 15% of your grade. Describe any non-trivial data structures you have used, and briefly say how each relevant routine acts on those data structures. Do not simply echo the specifications given here.

Do not use the system() system call or invoke the UNIX shell to implement your shell!

You must do the project described here. Doing some other similar or dissimilar project, matter how difficult or clever, may be worth 0 points. This is not a group project; please do your own work, and be careful about sharing your code. It is OK to discuss design issues, but in your documentation, you should give credit to your sources.

What to turn in

When your project is absolutely finished and you have completely and totally tested your work, you are to create a script file (the output is "typescript" as in the following example (where "$" is the UNIX prompt):
$ script
$ cat mysh.c
$ cc -o mysh mysh.c
$ mysh
mysh  /* run examples to prove all internal commands and
         all forms given about will work. */
mysh exit
$ exit

Mail the file typescript to the TA for grading. If your code is in more than one file, you will have to "cat" each file, and then "cat" the makefile, if you are using one.

Hints and Tips


webmaster@cs.umbc.edu   |   UMBC   |   CSEE   |   User pages   |