Assignment 2, due Jan. 30

Part of the homework for 22C:112, Spring 2009
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

  1. Background: The C source file http://homepage.cs.uiowa.edu/~dwjones/opsys/shell.txt Contains a working command shell that should work under most Unix systems.

    a) There are 4 #include directives. Each of them makes some of the function calls in the program legal. Which functions does each include directive make legal? An empirical approach may be the easiest way to answer this -- see what error messages result from deleting each #include directive. (0.5 points)

    b) The code exit(0) is used to exit the shell when it hits an end-of-file or when it encounters an exit command. The Unix standard discourages using this naked constant, and recommends that exit() be called with specific symbolic constants indicating success and failure. What are the recommended constants and which header file are they in? Hint: It's the same header file that allows you to call exit() in the first place. (0.5 points)

  2. Background: Consider this shell script, stored in the executable file script:
    # script
    script | script
    

    a) What does it do? Answer this by reading the text. (0.5 points)

    b) Why, on early Unix systems, did it crash the system? Trying it might help answer this. (0.5 points)

  3. A Problem Write a shell script that, given an integer argument i outputs the successive integers 1 to i. (1 point)