CS439: Principles of Computer Systems

Homework 1

(Source: Alison Norman.)

Due: 8:45 AM Tuesday, January 22, 2013

Homeworks will be submitted electronically. Please refer to the homework turnin instructions.

  1. Which of the following components is responsible for loading the initial value in the program counter for an application program before it starts running?
    • Compiler
    • Linker
    • Loader
    • Boot module or boot ROM
  2. From Anderson and Dahlin, Ch1 question 1:
    Suppose a computer system and all of its applications are completely bug free. Suppose further that everyone in the world is completely honest and trustworthy. In other words, we do not need to consider fault isolation.

    • How should the operating system allocate the processor? Should it give all of the processor to each application until it no longer needs it? If there are multiple tasks ready to execute at the same time, should it schedule the task with the least amount of work to do or the most? Justify your answer.
      You may assume a uniprocessor.
    • How should the operating system allocate physical memory between applications? What should happen if the set of applications does not all fit in memory at the same time?

    Note: These are thought questions---you are not expected to determine how operating systems currently solve these problems. Instead, you should think about how you would solve the problem.

  3. From Anderson and Dahlin, Ch1 question 2:
    Now suppose the computer system needs to support fault isolation. What hardware and/or operating support do you think would be needed to protect an application's data structure in memory from being corrupted by other applications? Assume more than one application may reside in memory at a time.
    Again, a thought question.
  4. What differentiates a program, an executable, and a process?

  5. Define three styles of switching from user mode to supervisor mode.
  6. Given the following piece of code:
       main(int argc, char** argv)
       void forkThem(int n)

    How many processes are created if the above piece of code is run?
    Inspect the manual for the system calls if you need more information, but please solve the problem without compiling and running the program. It may be easier to solve this problem by induction.

  7. System Calls vs. Procedure Calls: How much more expensive is a system call than a procedure call? Write a simple test program to compare the cost of a simple procedure call to a simple system call ("getuid()" is a good candidate on UNIX; see the man page.) (Note: be careful to prevent the optimizing compiler from "optimizing out" your procedure calls. Do not compile with optimization on.)
    • Explain the difference (if any) between the time required by your simple procedure call and simple system call by discussing what work each call must do (be specific). [Note: Do not provide the source code for your program, just the results].

    Hint: You should use system calls such as gettimeofday() for time measurements. Design your code such that the measurement overhead is negligible. Also, be aware that timer values in some systems have limited resolution (e.g., millisecond resolution).