CMSC421

Principals of Operating Systems

Sections 0101/0201/0301

CSEE

Programming Project #2

Assigned: 13 Nov 2002

Project Due: 5 Dec 2002 at 11:59 pm

             27 Nov 2002 at 11:59 pm for ten percent extra credit  25 Nov

Updated: 18 Nov

Project 2: Implementing a Simple Shell

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

Project Goals

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

The Project

Shell

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"), the user's date command ("date"), the history command ("history"), command to restart the client ("restartclient") 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 */

    /* Here you would have to check to see if                         */ 
    /* exit was entered and if it was, break out of the loop.         */
    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      */
        exit( 0 );                        /* when sucessful, there is */
                                          /* no return from execve    */
    }
}
Check the documentation for the exec calls to see what is the int character arrays command and parameters.

Pipe and Sockets

You are to design and implement file-transfer system that use two Linux systems (such as Linux1, Linux2, and lab computer running under Linux). There will be two independent programs client and server. You will have to log into both systems and designed which machine is which. On the server side, you will start the program server which will monitor the socket, waiting for commands. It is important that you start the server first and then the client. If the server terminates for any reason, you must kill the client and then restart the server and then the client.

There will be a 20% penatly if this part is not implemented!

On the client side, mysh will create a pipe and execute the program client. The client will wait until it receives a command on the pipe from mysh. Commands that it will be expected to handle are:

  1. remoteput
  2. remoteget
  3. remotels
Files of any size can be transferred, so you will have to coordinate the flow of data across the pipe so that the data being sent does not overrun any buffers.

You will need to run a unique port number, so use 4XXXX, where "XXXX" is the last four digits of your SSN. If there are any programs, to 5XXXX instead, and document the change!

Sample of the socket code:

Client side
Server side

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:

Extra Credit Feature

UNIX has three different types of quotation marks:

Single Quote

Anything inside a single quote is to be taken as a constant that should not be modified.
'Hello'

Double Quote

Inside double quotes, variable names are replaced by the variable contents:
echo "$HOME"
/home/faculty1/burt

Single Back Quote

If a command contains something inside a single back quotes, it tells the shell that it is to run the command that is inside the single back quotes and replace the what is inside the double back quotes with the results of this second command and use it to execute the first command:

Exampele:

burt[103]: echo `whoami`
burt
In this case, the command "whoami" returned the results of whoami (which is "burt" and the command became
echo burt

Another example is:

burt[105]: echo "It is currently `date`"
It is currently Wed Nov 13 17:01:06 EST 2002
The date command returned the string "Wed Nov 13 17:01:06 EST 2002" and turned the command into:
echo "It is currently Wed Nov 13 17:01:06 EST 2002"

The command

finger `whoami` became finger burt and produced the results of:

burt[106]: finger `whoami`
Login: burt                             Name: Gary Burt
Directory: /home/faculty1/burt          Shell: /bin/csh
Never logged in.
New mail received Wed Nov 13 16:37 2002 (EST)
     Unread since Tue Nov 12 17:12 2002 (EST)
No Plan.

A final example is:

echo "You have `ls | wc -l` files in this directory."
produces the output of: You have 55 files in this directory. Your mission, Mr. Plelphs, is to implement the single backquote in your project for 5% extra credit.

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. Describe any non-trivial data structures you have used, and briefly say how each relevant function acts on those data structures. Do not simply echo the specifications given here.

The coding standard and indentation standards must be following and compliance will be part of the 20% for documentation!

There are 40 commands that I have given to the TAs to be used when grading the project that will make up the other 80%.

Do not use the system( ) system call or invoke the UNIX shell to implement your shell!
Doing so will earn you a zero on the project!

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.

You will be provided with a copy of the test plan that the TAs will use when the grade this project, so that you will know exactly how they will test this project. However, you must make sure that you can meet all the requirement in any of the prescribed forms! The TA will be allowed to run any commands necessary to give the proper grade. You can not limit you programs to just those commands on the webpage, either!

What to turn in

You must have a makefile, design document, all source code and a README file. If your code is in more than one file, you will have to a makefile. For help with a makefile, see the TA. You are to provide all necessary instructions on how to build and execute your programs in the README file, so that the TAs can do the best job of building and testing your system. Anything that you feel will help the TA should be included. Do not turn in any executables or binaries!.

Put all of the required files into a tar file and

When your project is absolutely finished and you have completely and totally tested your work, you are to submit the project tar file for grading using the digital dropbox in Blackboard.

It is important that your tar file be named with the last four digits of your SSN and "prj2". If the last four of your SSN were 6789, then the file name would bd:

6789prj2.tar The TA's will deduct points if you do not correctly name your file.

Hints and Tips


UMBC   |   CSEE