CSE 120: Homework #1

Fall 2023

Due: Thursday October 12 at 11:59pm

Each question is worth 5 points. When a question asks you to describe or explain, your answers can be relatively brief. The [name] tags give scholarly attribution to authors of other OS textbooks who wrote the question (you do not need those textbooks to be able to answer the question, though). You may type or handwrite your answers.

You will submit your homework electronically via gradescope. Once you have logged in, follow these general instructions for uploading your homework (we will post to piazza when gradescope is ready for submissions).

  1. [Anderson 2.1] For each of the three mechanisms that supports dual-mode operation — privileged instructions, memory protection, and timer interrupts — explain what might go wrong without that mechanism, assuming the system only had the other two. (In other words, if we just had memory protection and timer interrupts but not privileged instructions, what could go wrong; if we just had privileged instructions and timer interrupts, what could go wrong, etc.)

  2. You may have written programs that call exit, or return from main with some value, and wondered what happens to that value. The value can be returned to a parent process when the parent calls wait on the child: if the child calls exit(0) then the value 0 can be returned to the parent via wait. Why have this functionality, why might it be useful?

  3. [Silberschatz] Which of the following instructions should be privileged? Give a one-sentence explanation for why.

    a) Set value of timer
    b) Read the clock
    c) Clear memory
    d) Turn off interrupts
    e) Switch from user to monitor (kernel) mode

  4. [Tanenbaum] For each of the following Unix system calls, give a condition that causes it to fail: open, read, fork, exec, unlink (delete a file). (Hint: We discussed some in lecture, and you can also explore the error semantics of these system calls using man on ieng6, e.g., man 2 fork.)
  5. On Unix, two signals that cannot be caught and handled by an application are SIGKILL and SIGSTOP.

    a) SIGKILL immediately terminates a process. What is a scenario that motivates having the OS make it impossible for an application to handle SIGKILL?

    b) SIGSTOP immediately pauses a process (which can later be resumed with SIGCONT). Why is it safe (in terms of application correctness) for an application to be arbitrarily paused using SIGSTOP?

  6. [Crowley] Suppose the hardware interval timer only counts down to zero before signalling an interupt. How could an OS use the interval timer to keep track of the time of day?

  7. [Anderson 2.13] Suppose you have to implement an operating system on hardware that supports interrupts and exceptions but does not have an explicit trap (syscall) instruction. Can you devise a satisfactory substitute for traps using interrupts and/or exceptions? If so, explain how. If not, explain why. (In this context, the trap instruction is the instruction used by a user-level process to invoke a system call in the operating system, i.e., the trap instruction is the system call instruction.)

  8. Consider the following C program:
    #include <stdlib.h>
    int main (int argc, char *arg[])
        if (fork ()) {
    	fork ();
        } else {
            fork ();
    	char *argv[2] = {"/bin/ls", NULL};
    	execv (argv[0], argv);
            fork ();

    a) How many total processes are created (including the first process running the program)? (Note that execv is just one of multiple ways of invoking exec, see man 3 exec for all possibilities.)

    b) How many times does the /bin/ls program execute?

    [Hint: You can always add debugging code, compile it, and run the program to experiment with what happens.]