Home CS439

CS439: Principles of Computer Systems

Homework 10, Part 1

Due: 8:45a Friday, April 24, 2015

Part 1 of the homeworks must be submitted electronically. Please refer to the homework turnin instructions.

  1. What are the three methods of switching from user mode to supervisor mode? When might each occur?

  2. Given the following piece of code:
    main(int argc, char**argv)
       int child=fork();
       int c=2;
    How many different copies of the variable c are there? What are their values?

  3. Describe the priority inversion problem and give an example situation where it may occur.

  4. In Unix, the pipe(2) function call creates an I/O mechanism called a pipe and returns two file descriptors, fd[0] and fd[1]. The files associated with fd[0] and fd[1] are streams of data and are both opened for reading and writing. Suppose pipe always returns the two lowest-numbered file descriptors in the process's file descriptor table that are unused. Assume that initially fdt[], the file descriptor table, has three open entries: fdt[0] is the default input device, fdt[1] is the default output device and fdt[2] is the default error output device; all other entries of the fdt are NULL. What does the fdt look like after each of the five following commands is executed in sequence by the process?

    1: pipe (&fd[0]);
    2: close(fd[0]);
    3: close(1);
    4: dup(fd[1]);
    5: close(fd[1]);

    When might such a sequence of commands be useful?

    You'll need to use the man pages for pipe, close, and dup to answer this question.

  5. In two-phase commit, suppose the master fails after writing ``GLOBAL_COMMIT'' to disk and sending ``GLOBAL_COMMIT'' to all participating nodes but before any of the nodes receive this message. Suppose that the ``GLOBAL_COMMIT'' message reaches i of the n participants and that the participants implement a protocol in which they communicate with one another when they suspect the primary has died. What is the minimum number of participants that must receive the ``GLOBAL_COMMIT'' message to allow the participants to complete the transaction without waiting for the master to recover?