Assignment 8, due Oct 27

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

Machine Problem Due Nov 5

Write a shell that runs under Linux (or any other Unix compatable operating system) that supports input-output redirection using the > and < operators, as in the standard Unix shell.

For your starting point, use the extremely minimal shell provided. This supports only the most rudimentary form of command, with only one advanced feature, a search path. You can load the shell from:

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

Warning: That little shell works perfectly, and it even contains, in its header comments, pretty good documentation of what it does. The only thing is, it's written for minimality, not as a clean foundation for developing a bigger shell. Most of the program is in main(), and that's classic evidence of poor programming even in a file this size! It hasn't got a good parser at all! You may want to do some housecleaning before you take off and start doing this machine problem. How much you do of this is entirely your problem! Do too little, and you'll likely have a hard time adding the extensions. Doo too much, and you'll spend all your time reengineering the shell. In any case, the example shell is only 203 lines long, so you really do have time to read and understand the whole thing before you set off to modify or fix it.

Regarding I/O redirection. Any file you open or close between the time you call fork() and the time you launch the new application with execve() will have an effect only on the new application and will not have any long term effect on the running shell. Input-output redirection should be done at the level of the primitive Unix file system, using open() and close(), not the level of C (or C++) input-output streams (the level of freopen()). Use the commands pages for man 2 open() and man 2 close() for information on these. The 2 forces the man command to look in section 2 of the Unix/Linux programmer's reference manual for primitive kernel calls. Section 1 covers the command line interface, while Section 3 covers the standard C/C++ library.

Homework Due Oct 27

  1. Do chapter 11 problem 5.

  2. Do chapter 11 Problem 7.

  3. Do chapter 11 Problem 13.

  4. Do chapter 11 Problem 14.