DOC PREVIEW
UNO CSCI 4500 - Operating Systems

This preview shows page 1-2-3 out of 8 pages.

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

Unformatted text preview:

Computer Science 4500/8506 Programming Assignment 1 Fall 2011UNIVERSITY OF NEBRASKA AT OMAHAComputer Science 4500/8506Operating SystemsFall 2011Programming Assignment 1IntroductionThe purpose of this programming assignment is to give you some experience with processes andinput/output at the system-call level in UNIX. You will need to use at least the access, fork, execve,read, write, wait and exit system calls. Make certain you read and understand all of the materialin the assignment.The program you write will be a simple command line interpreter, or shell. It will not have nearly asmuch functionality as any of the typical shells found on a UNIX system. Instead, it will deal only withrunning processes and interpreting a subset of the execution sequencing operators provided by a full-featured shell.The heart of your program is the creation of a process using the fork system call, and the execution of aspecified program with a specified list of command line parameters by that process using the execvesystem call. In “shell-speak” the commands your program can execute are simple-commands:A simple-command is a sequence of non-blank words separated by blanks (a blank is a tabcharacter – '\t' or 0x09 – or a space – ' ' or 0x20). The first word in the sequencespecifies the name of the command to be executed. All of the words are passed as argumentsto the invoked command. The command name is passed as argument 0. The value of asimple-command is its exit status if it terminates normally, or 128 + its exit status (non-zero)if it does not terminate normally.A word is just a sequence of non-blank, non-tab, non-end-of-line characters. We will assume that all thecharacters in a word are printable ASCII characters; that is, they are in the range 0x21 to 0x7e ('!' to'~'). More detail on the execution of a simple-command is given later in the assignment.The input to your program (which is read from the standard input, file descriptor 0) is a sequence of lines(each of which will be no longer than 100 characters and terminated by an end of line character, '\n'),each line containing a list of simple-commands. Each pair of consecutive simple-commands in an inputline is separated by one of these three:';' (semicolon) – The commands separated by a semicolon are executed sequentially, one at atime, with the left command executed first.'&&' (logical and) – The left command is executed first. The right command is executed only ifthe left command returns a value of 0.'||' (logical or) – The left command is executed first. The right command is executed only ifthe left command returns a non-zero value.'&&' and '||' have equal precedence (when treated as operators), and they have higher precedencethan ';'.Computer Science 4500/8506 Programming Assignment 1 Fall 2011Process/Program Return ValuesWhen we talk about a program or process “returning a value,” we’re referring to the value returned bythe main function (in a return statement), or the value specified as the argument to the exit systemcall. Consider the following simple program:int main(int argc, char *argv[]){if (argc == 2)return atoi(argv[1]);elsereturn 1;}This program expects that it is invoked with an integer argument (in addition to the name of theprogram). If not, then it returns with the value 1. Otherwise it uses the atoi function to convert theargument to a binary integer which is the value returned by the program. Of course the return statementsin this program could have been replaced by invocations of the exit system call, and the effect wouldhave been identical (except that we needed to include stdlib.h to provide the declaration of theexit system call for the C compiler):#include <stdlib.h>int main(int argc, char *argv[]){if (argc == 2)exit(atoi(argv[1]));elseexit(1);}The value returned from a process by the main function or by the exit system call is limited to a widthof 8 bits by most UNIX systems, so the range of values that can be effectively returned is 0 to 255. If alarger value is specified, only the low-order 8 bits will be retained.ExamplesLet’s consider some example command lines. Each of these can be executed on vulcan, and it isrecommended that you experiment with the execution of these (and additional variations) to ensure yourunderstanding of them. In these examples we’ll use some simple programs. true and false arestandard UNIX programs that do nothing except return values of 0 and non-zero respectively. echo justdisplays the words provided as command-line arguments, so the command echo Hello will justdisplay the word Hello. Note that the standard shells on UNIX systems will replace some command linearguments. In particular, the command line argument $? is replaced by the value returned by the lastcommand executed.echo one ; echo two ; echo three – This sequence will just cause three lines to bedisplayed containing the words one, two and three.echo one ; echo $? – This will display a line containing the word one, then a linecontaining the exit status of the echo one command, which is 0.Computer Science 4500/8506 Programming Assignment 1 Fall 2011echo one || echo two – This will just display the word one, since the value returned byexit is zero.echo one && echo two – This will display one, then two.false || echo two – Displays two.false && echo two – Displays nothing.echo one || echo two || echo three – Displays one.false ; echo one || echo two – Displays one.true && echo one ; false && echo two – Displays one.echo one two three && echo four – Displays two lines, one with one twothree, and the other with four.Make certain you understand what the shell is doing for these cases before you implement your solutionto this assignment! If you are brave (or curious), you can use the command man sh to view areasonably terse description of the full-featured shell used on vulcan.Problem StatementSpecifically, you are to write a program that will repeatedly do the following things, repeatedly:1. Read a command line from the standard input (file descriptor 0). At the end of file (that is, whenthe read system call returns 0), just quit (using the exit system call).2. If the line just read contains only blanks and tab characters, ignore it, and return to step 1.3. Identify the words on the command line. Each word is just a sequence of non-blank (blank or tab)characters. In this shell we assume at least one blank or tab character separates each word fromthe next. We also assume that whitespace is


View Full Document

UNO CSCI 4500 - Operating Systems

Download Operating Systems
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 Operating Systems 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 Operating Systems 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?