Assignment 10, due Apr. 23

Part of the homework for 22C:112, Spring 2010
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: A Unix process has at least the following fields in its process description data structure:
    -- r, the register save area
    -- f, the table of open files
    -- c, the pointer to the process's code segment
    -- g, the pointer to the process's static segment
    -- s, the pointer to the process's stack segment

    When there is a system call that has a return value, the system call trap service routine stores the return value in a designated register of the calling process. Call this the return register, r[return].

    A Question: The fork() kernel call must create a new process description by copying some of these fields from the calling process description and changing others. Give detail, for each field, what is copied and what is changed. (1.0 points)

  2. Background: Consider this user level thread package:
    This thread package is entirely a user-level package, with minimal interactin with the kernel. It is entirely normal 32-bit user code.

    Look at the code for thread_relinquish(). The function of this code is very similar to the function you would expect from the real-time clock interrupt service routine in the kernel, except that threads call it voluntarily when they wish to let other threads have a chance at the CPU. You will need to look up some routines in the C standard library to understand how this code works. Use the man command, or google, to look these up.

    A Question: With the real-time clock service routine, entry to the interrupt service routine saves the state of the former running process, and exit from the interrupt service restores the state of the new running process. How does the state of the former running thread get saved and how does the state of the new running thread get restored in the thread manager's relinquish routine? (1.0 points)

  3. Background: Semaphores were an afterthought in Unix. Classic Unix utilities, therefore, did not use semaphores for mutual exclusion. Instead, they used lock files. For example, if the file f is shared between applicaitons, the lock file fl might be used for mutual exclusion during access to f. If the lock file exists, f is in use. If the lock file does not exist, f is free and may be used.

    a) Give appropriate C code for exit from a critical section. This is just a matter of deleting the lock file. (0.5 points)

    b) Give appropriate C code for entry to a critical section. This requires creating the lock fiel with file creation options set to notify the caller if creation failed because the lock file already existed. (Hint. Each time around the polling loop, it is appropriate for the calling process to sleep for a moment to give other processes a chance to run.) (0.5 points)