CS 307
Midterm
Due 8:30AM Wednesday, May 8, 1996

Use your textbook, your notes, local on-line Unix documentation, your brain, or your psychic powers, but don't use other people, books, or Internet resources.

  1. When I taught this course in 1994, I asked the students to rewrite Peterson's solution on page 37 of Tanenbaum for N=3. A typical answer to this homework problem looked like this:
    
    void enter_region( int process )
    {
    	int	other1, other2;
    
    	other1 = (process+1) % N;
    	other2 = (process+2) % N;
    
    	interested[process] = TRUE;
    	turn = process;
    
    	while( turn==process &&
    	    (interested[other1]==TRUE || interested[other2]==TRUE) )
    		;
    }
    
    void leave_region( int process )
    {
    	interested[process] = FALSE;
    }
    

    The following is Peterson's pseudo-code for his own n-process solution, from the 1981 paper cited in Tanenbaum. There are n processes numbered 1 through n. Q[] and TURN[] are shared variables, while j and k are local to each process.

    
    /* Code for process i */
    
    /* Enter region */
    for j := 1 to n-1 do
    begin
    	Q[i] := j;
    	TURN[j] := i;
    	wait until (for each k<>i, Q[k] < j) or TURN[j] <> i
    end;
    
    /* Critical section */
    Critical section;
    
    /* Leave region */
    Q[i] := 0;
    
  2. Do problems 11 and 15 on pages 142-143 of Tanenbaum.
  3. Suppose an operating system uses inodes to keep track of files. Suppose further that each inode contains 8 direct block numbers, and the block numbers for one single indirect block, one double indirect block, one triple indirect block, and one quadruple indirect block. Suppose blocks are 512 bytes long, and block numbers are 32-bit unsigned numbers.

  4. Here are a few questions about processes in Unix. You can answer these questions by writing simple C programs. Do so, and include the programs (and output, if appropriate) with your answers.