Assignment 2, Solutions

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

  1. Background: Consider this perhaps less than trivial C program:
    #include <stdio.h>
    #include <stdlib.h>
    int main( int argc, char *argv[] ) {
       if (argc <= 0) exit( EXIT_SUCCESS );
       argc = argc - 1;
       puts( argv[argc] );
       main( argc, argv );

    You may find the man command to be very important in understanding this program. The Unix shell command man 3 exit will output the manual page on the exit() routine in the standard library. Section 3 of the manual is the standard library. You can look up puts the same way. Kernighan and Richie has a discussion of the main program, and Google (or Bing, or Yahoo) can find writeups on all of this. (0.4 points each)

    a) What order does the program output its command line arguments in?

    Reverse order.

    b) The main() function is recursive. Does it ever return?

    The recursion is used entirely for iteration. The entire program terminates by a call to exit() and none of the calls ever return.

    c) What is argv[0]?

    This holds the command name used to launch the program -- some version of the file name, as it was typed on the command line.

  2. Background: In 1974, Ritchie and Thompson's article on the Unix Time-Sharing system was published in Communications of the ACM. See

    A Question: What did Ritchie and Thompson claim was original in their invention of Unix? (0.9 points)

    Section 8.1 is a denial of originality. The primary contribution of UNIX was integration of ideas that came from prior systems. In fact, the set-user-id mechanism discussed in Section 3.5 is original but the paper does not make this claim with any force. (It is outside the scope of this question to note that US Patent 4,135,240 was granted to Ritchie in 1979 covering the set-user-id bit.)

  3. Background: Going back in time, in 1966, Lampson and Lichtenberger published an article on A user machine in a time-sharing system in the Proceedings of the IEEE. See

    A Question: Programmers on this machine thought that they were writing code on a physical machine, but the system provided services that let them reconfigure the machine. How? (0.9 points)

    A number of SYSPOP instructions were defined by the system (effectively, by the trap handler for undefined instrucitons). SYSPOPS were used to perform such reconfiguration (for example, changing the memory mapping of the running program).