Home CS439

CS439: Principles of Computer Systems

Discussion Section Problem Set 1

Due in Section on Friday, September 8, 2017

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. Create a name tent for use during all discussion sections this semester. Your name tent must be typed and your first name (or the name you would like to be called) must be displayed in a font size of at least 78pt. Your last name should be on the next line and must be displayed in a font size of at least 48pt. If you are unsure of either what a name tent is or how to create one, many examples can be found using Google (probably the one and only time this semester we will recommend Google). Bring your name tent with you to discussion section (there is no need to turn it in to Canvas).
  2. While holding your name tent, capture a picture of yourself and upload it to the Section 1 assignment in Canvas. The picture must be appropriate, we must be able to read the name tent and see your face, but the rest is up to you.
  3. What are "privileged instructions"? Name three situations in which privileged instructions are required.

  4. 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).

  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.