Assignment 3, due Feb. 2

Part of the homework for CS:3620, Spring 2018
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On all assignments, your name must be legible as it appears on your University ID card! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what lawyers call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the teaching assistant's mailbox. Never push late work under someone's door!

  1. Background: If you run mush, you'll find that it works for commands like /bin/echo and /bin/vi but it fails when you try to compile a program. Here's a transcript of what happens:
    >/bin/cc -o mush mush.c
    collect2: fatal error: cannot find 'ld'
    compilation terminated.

    The problem is, /bin/cc relies on a search path that's part of the default environment.

    A problem: Fix it. Everything you need to know to fix this is in the notes for Jan. 26. Only two lines of code are involved, so give your fix in the form of notes that explain what lines of code to add, delete or change. (1.0 points)

  2. Background: The notes for Jan. 29 describe the relationship between character-sequential and line-sequential input. Inside an operating system that provides both, it is possible that ...

    The getcommand() function in our minimal shell mush only uses getchar() to read lines. It could have used fgets(command,100,stdin) to read an entire line of text instead of using a loop of repeated calls to getchar().

    A problem: Experiment with replacing the loop of repeated getchar() calls in mush with a single call to fgets() for reading the input command line. Study its behavior, with the goal of trying to figure out how getchar() and fgets() are related (that is, which of the three alternatives above describes their relationship.)

    Identify the relationship and support your conclusion with descriptions of the observed behaviors that convince you of that relationship. (1.0 points)

  3. Background: The linux linker is called ld. By default, the cc command finishes the job of compiling by using ld to link the compiled program with the C standard library. The error discussed in the preface to 1 appears to be the result of cc using an environment variable in order to find where to look for ld.

    We have already discussed the standard shell's search path, which it gets from the environment variable PATH. The following questions are best answered by a bit of judicious googling (lower case, because I use this verb to refer to use of any search engine).

    a) Name some of the search paths that the cc command uses that are not involved with linking. (0.5 points)

    b) Name at least one search path that the cc command is documented as using but is actually used by the linker. (0.5 points)