Assignment 7, due July 11

Includes Machine Problem 4, due July 17

Part of the homework for 22C:50, Summer 2003
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

 

Machine Problem 4

Ground rules: The ground rules distributed with MP1 hold for this assignment!

Background: A minimal Unix shell (command-line interpreter) allows is available on-line, at:

http://homepage.cs.uiowa.edu/~dwjones/syssoft/hw/mp4basis.txt

This shell has one built-in command, exit, that causes it to terminate. For all other lines of input, excepting blank lines and lines starting with comments, it parses the lines into words (separated by blanks) and tries to use the first word on the line as the name of a program to run, passing the words on the line as arguments to the program. If the first word on the line doesn't work as a filename all by itself, this shell tries prefixing it with, /bin and then with /usr/bin before giving up, since most commonly used commands are found in one or the other of those directories.

Part I: This shell works, you should try it and try writing some shell scripts to test it out, but it is horribly written! Most of the functionality of the program is in one oversized block of code, even though, logically, you can clearly see that this program does lexical analysis, syntax analysis and semantic action as it processes its input.

Before anyone tries enhancing this program, it should be modularized. Break it up into multiple source files. At minimum, you should break out as a separate file the mechanism for executing shell commands (both built-in and other) and separate that from everything having to do with parsing, but you can do more.

To do this, you should create appropriate header files, package the whole thing in a directory, and create a Makefile and a README file, writing content for them, or cutting and pasting, as needed, from the code that was distributed in order to build them.

Note: Obviously, borrowing heavily on the EAL assembler is a good idea -- not borrowing C source code, but borrowing layout and structure for the different files.

Another Note: Please: Do this incrementally! First compile and test the shell, then write the makefile, then build and test again, using make to do the build. Then split off one function, make it and test it again, and so on.

Part II: This shell has a hard-coded list of directories to try when attempting to execute a command, trying different prefixes on the command name until one of them works! This should be rewritten as a loop, iteratively attempting each prefix from a list of prefixes, and getting the list from the environment variable PATH, where it is stored as a single string, with fields separated by colons. For information on the environment, see man environ. The standard library routine getenv() is helpful for extracting a single entry from the environment.

Part III: Add a new built-in command, setenv, that takes argv[1] as the name of an environment variable and argv[2] as the new value for that variable.

Homework 7

  1. What is the output from the parser that serves as input to the command execution code in the example shell distributed with the assignment for MP4?

  2. Do problem 6, part a) from page 162 in the test, but substitute the following for parts b) and c):

    Part b) Explain the economic problems posed by this implementation in a system that uses a queue of characters for output to a printer, so that an application may enqueue thousands or millions of bytes of data long before the printer finishes printing the first page of the document.

  3. With reference to Figure 10.14 and the accompanying text, which echo path do UNIX keyboard drivers use? This is a question that can be answered empirically by doing experiments on a Unix system that take a few minutes, at most. (Note that some Unix applications turn off echoing by the system so they can do it themselves! Clearly, you shouldn't run these applications as part of your experiment).

    Note: You should describe, briefly, the experiment you performed in order to figure out the answer to this question. A "naked" number will not be given full credit.

  4. Do problem 10 on page 162 of the text.