DOC PREVIEW
UE CS 470 - LECTURE NOTES

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 470 - Operating SystemsSpring 2011 - Shell Project (OPTIONAL)40 pointsOut: April 4, 2011Due: April 25, 2011 (Last day of class)This project is OPTIONAL. If you choose to complete this project, its score will replace the lowest score among the three required projects. This project is due no later than the last day of classes. NO LATE WORK will be accepted for this project.The purpose of this project is to provide experience with process manipulation in Unix.Problem Statement1This project consists of completing a program to serve as a shell interface. That is, the program accepts user commands and then executes each command in a separate process. Unless otherwise specified, the parent process waits for the child to exit before continuing as shown in Figure 3.11 in the textbook. As is typical, the shell also will allow the child process to run concurrently by specifying the ampersand (&) at the end of the command. And finally, the shell will support a history mechanism that allows users to repeat commands previously entered.Project DetailsThis project is organized into two parts: 1. Create a child process that executes the given command that the parent may or may not wait for using the fork(), exec(), and wait()/waitpid() system calls (described in Section 3.3 of the textbook)2. Implement a history mechanism.The base shell code code described below is written in C (though it is in a C++ file) and is available in the directory /home/hwang/cs470/project4. However, this project may be written in any language as long as it supports OS-level process creation, and runs on csserver.Simple ShellThe program in shell.cpp provides the basic operations of a command line shell. The program consists of two functions: main() and setup(). The setup function reads in the user's next command (up to 80 characters), and then parses it into separate tokens that are used to fill the argument vector for the command to be executed. Note that the setup function creates the args array by manipulating inputBuffer. (That is, inputBuffer is modified by the function.) It replaces all whitespace and any & in inputBuffer by the null terminator. The elements of args are pointers to the first letter of each word in inputBuffer. If an & is encountered, the background parameter is set to inform the main program. The program is terminated when the user enters Ctrl-d which causes the setup function to invoke exit().1 This project is based on the UNIX Shell and History Feature project published in previous editions of the course textbook: Sibershatz, Galvin, and Gagne, Operating Systems Concepts, 7e, John Wiley & Sons, Inc., 2005.04/03/2011 Page 1 of 3The main function presents the user prompt and then invokes the setup function, which waits for the user to enter a command. When the setup function returns, the args array is suitable for passing on to the execvp() system call. For example, if the user enters "ls -l" at the prompt, args[0] is the C-style string "ls" and args[1] is the C-style string "-l".Creating a Child ProcessThe first part of the project is to modify the main function so that upon the return of the setup function, a child process is forked and executes the command specified by the user using the execvp() system call, which has the following interface: execvp(char *command, char *params[]);where command is the command to be performed and params stores the parameters to this command. Thus for this project, the call should be execvp(args[0], args). The background variable determines whether the parent process is to wait for the child to exit or not.Creating a History MechanismThe second part of the project is to add a history mechanism that allows the user to access up to the 10 most recently entered commands. The user will be able to list these commands using the "built-in" shell command history. That is, when the user types in history as the command, the shell should recognize this and print out a list of the 10 most recently entered commands.From the history list, the user can run any of the previous 10 commands by entering "!x" where 'x' is the first letter of that command. If more than one command starts with 'x', the most recent one is executed. Also, the user should be able to run the most recent command again by entering "!!". It may be assumed that '!' cannot start a command name, that there is no space between '!' and the letter, and that the letter will be followed by a newline. Likewise, "!!" will be followed immediately by a newline if the user wants to execute the most recent command. Any command executed in this manner should be echoed on the screen and placed in the history list as the next command. Note that this is the actual command executed, not "!x" or "!!". If the user attempts to use the history mechanism incorrectly (e.g., there is no command starting with 'x'), an error message should be displayed and the command is not entered into the history list. And of course, execvp should not be called. Note this is only for history usage errors and will not prevent erroneous commands that appear to be valid from being added to the history list and attempted to be executed; handling this is beyond the scope of this project.Assignment(20 points) Implementation. This project is to be done individually. Provide a makefile that will make your project if it needs to be compiled.(10 points) Provide a high-level functional analysis and design of the program describing the functionality of the major components of the program and how they interact with each other, and a more detailed analysis and design for the data structures and algorithms used in the history feature portion of 04/03/2011 Page 2 of 3the program. If the program does not meet all of the project requirements, describe which parts are missing and what you think should be done to implement them.(10 points) Provide a test plan for your project. I.e., give a list of commands that will demonstrate the features of your shell. Annotate this list with notes regarding what result is expected. The grade for this portion of the project will depend on how thorough the test plan is. Note that the test plan should cover all of the project requirements whether or not the program actually implements them.In addition, answer the following questions: 1. What aspect of process manipulation did you find most difficult to understand? 2. What aspect of process manipulation did you find least difficult to


View Full Document

UE CS 470 - LECTURE NOTES

Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?