Home CS439

CS439: Principles of Computer Systems

Homework 2, Part 1

Due: 9:45a Thursday, September 10, 2015

Part 1 of the homeworks must be submitted electronically. Please refer to the homework turnin instructions.

  1. Run the following command in your command line (it generates 10k random integers less than 100 and stores them in the num.txt file.):
    $ for i in {1..10000}; do echo $(($RANDOM % 100)); done > nums.txt

    Note that in this command line, $ indicates the shell prompt.

    How many 12 are in num.txt? How many 10? How many 87?
    What command did you use to answer this question?

    Hint: You don't even need to open the file to answer this question. You may find grep and wc useful.

  2. Open a terminal on a departmental Linux machine. After ensuring that you are in a bash shell, use the time command to measure the time taken by a Linux command that sends output to the screen (and maybe other things as well). You may use any Linux command you like. For instance, a sample run might be (from your Project 0 directory):

    time make

    Inspect the output. Explain the meaning of each line. Is the output as you would expect? Why or why not? Include your command in your answer.

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

  4. Given the following piece of code:
    main(int argc, char**argv)
       int child=fork();
       int c=2;
    How many different copies of the variable c are there? What are their values?
  5. 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.