Homework 1 for CS153
Instructions:
* Be brief. You will be graded for correctness, not on the length of your answers.
* Make sure to write legibly. Incomprehensible writing will be assumed to be incorrect.
1. OS is a
...
Homework 1 for CS153
Instructions:
* Be brief. You will be graded for correctness, not on the length of your answers.
* Make sure to write legibly. Incomprehensible writing will be assumed to be incorrect.
1. OS is a sleeping beauty. It can be woken up by four kinds of events. What are these events? Give an
example for each kind of event. (8 points)
2. Explain what happens in the computer when you press a key on the keyboard (Hint: read slides
about how the computer receives a packet from Ethernet). (6 points)
Answer:
3. What is a process? More specifically, what does a process contain? (10 points)
Answer:
4. There is a sleep system call in UNIX. It pauses the current process (who makes this system call) for a
specified number of seconds. Explain what happens in the OS kernel after this sleep system call is
invoked. (Hint: focus on process state transitions, wait queues, scheduling). (8 points)
Answer:
5. Run “sleep 3” and “exec sleep 3” in your shell respectively. Describe what happens and explain why
it happens this way. (Hint: think about how “fork” and “exec” work, check slide No.25 in lec05.pdf
for how a shell works.) (8 points)
6. Consider the following program:
Some explanation of the syntax:
● In C, when we have a condition such as that in line 6, we evaluate the first term and only if it is
true, do we execute the second term. If it is false, we do not evaluate the second term
(pid = fork()) in the same line executes the fork, assigns the return value to pid and uses that return
value to evaluate the condition.
● Count = count << 1 is a logical left shift by 1 bit. It’s a cheap way to multiply by 2 for integers
A. How many processes are created during the execution of this program? Explain. (4 points)
Total of three processes were created.
B. List all the possible outputs of the program. (6 points)
[Show More]