Home CS439

CS439: Principles of Computer Systems

Discussion Section Problem Set 2

Due in Section on Friday, September 14, 2018

The problem set must be completed before section and brought to section. To ensure that your problem set is turned in correctly and that you receive credit for discussion section, you must follow these guidelines exactly.

  1. What differentiates a program, an executable, and a process?

  2. 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?

  3. How can fairness and throughput be competing goals for a scheduler? Give an example where a fair scheduler makes bad use of the CPU and an example where a high-throughput scheduler is unfair.

  4. Most round-robin schedulers use a fixed size quantum. Give an argument in favor of and against a small quantum.

  5. Run the following command in your command line (it generates 10k random integers less than 1000 and stores them in the num.txt file.):
    $ for i in {1..10000}; do echo $(($RANDOM % 1000)); done > nums.txt
    Now, without opening the file, answer the following questions with both a) the answer and b) the command you used to find the answer.
    1. How many numbers containing 74 are in the file?
    2. How many 12s are in nums.txt?
    3. How many numbers in the file begin with 14?
    Hint: You may find grep and wc useful---use their man pages to learn more about them. In addition, The Geek Stuff as a tutorial on grep that you may find useful, and it also has a tutorial on regular expressions in the grep command.

  6. 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 gethrtime() or 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).