CS 321 Spring 2013  >  Assignment 1

CS 321 Spring 2013
Assignment 1

Assignment 1 is due at 5 p.m. Thursday, February 7. It is worth 25 points.

Procedures

This assignment may be turned in either in paper form or via e-mail.

Papers should be stapled and placed in my mailbox inside the CS Department office (202 Chapman).

E-mail should be sent to ggchappell@alaska.edu, using the subject “SA1”.

Exercises (25 pts total)

  1. Give an example of a virtual something that differs significantly from an actual something.
     
  2. When we make a system call, we are usually wanting to execute code that does something the current process is not allowed to do. What mechanism is used to solve this problem, and how does it work?
     
  3. System Call Actions. In each part, you are given some C++ code involving *ix system calls. Assume that the code compiles. If the code is executed, and none of the system calls fails, what will happen? Indicate what output will result, and when—if ever—each process will terminate. Note that the three code snippets are identical, except for the line marked with “<====”.
    1. 
      pid_t p = fork();
      if (p)
      {
          if (p < 0) _exit(1);
          int dummystatus;
          waitpid(p, &dummystatus, 0);
      }
      else
      {
          _exit(0);        // <====
      }
      write(1, "DONE\n", 5);
      _exit(0);
      
    2. 
      pid_t p = fork();
      if (p)
      {
          if (p < 0) _exit(1);
          int dummystatus;
          waitpid(p, &dummystatus, 0);
      }
      else
      {
          // HOWDY!        // <====
      }
      write(1, "DONE\n", 5);
      _exit(0);
      
    3. 
      pid_t p = fork();
      if (p)
      {
          if (p < 0) _exit(1);
          int dummystatus;
          waitpid(p, &dummystatus, 0);
      }
      else
      {
          while (true) {}  // <====
      }
      write(1, "DONE\n", 5);
      _exit(0);
      

     
  4. Parent Process.
    1. What is a “parent process”?
    2. What *ix system call returns the PID of the parent of the current process? (I do not think I have told you; it certainly is not in the lecture notes.)

     
  5. The kernel used in MacOS X, and NeXTSTEP before it, is not a microkernel. However it is based on the Mach microkernel. What considerations most likely led the developers at NeXT & Apple to move away from the use of a microkernel in their OSs? You have to guess, of course. Make a good guess.
     
  6. Multiprogramming generally results in more efficient processor usage than would result from a single process. That is, if there are multiple processes running, then the processor generally spends less of the time idle than if only once process is running. Why is this?
     
  7. Non-Blocking I/O. All the I/O we know how to do so far is blocking I/O, meaning that the process doing the I/O enters a blocking state until the I/O is finished. As a result, I/O functions do not return until the I/O is complete. An I/O function that does not wait for the I/O to complete before returning, is non-blocking.
    1. Explain how you could use the fork, write, and _exit system calls (and no other library functions or system calls) to do a non-blocking write. You may explain in words, or give C++ code for a non-blocking write function.
    2. Replacing “write” with “read” in the previous part would not give us a way to do a non-blocking read; we would need to use other system calls. Why? Hint: If you cannot figure it out, then try to write the code.

     
  8. The Linux kernel stores its process table as a doubly linked list of process control blocks (each of which is of type task_struct). It could have used an array instead of a doubly linked list. Give one advantage of a doubly linked list over an array, and one advantage that would have been gotten by using an array over a doubly linked list.
     


CS 321 Spring 2013: Assignment 1 / Updated: 1 Feb 2013 / Glenn G. Chappell / ggchappell@alaska.edu