Answer each of the following questions. Please submit your solution through Spark in either TXT or PDF format if possible.
1. (10 points) In each case, state whether the application would be better off using kernel or user level threads and why.
(a. ) A Bit Torrent application that must perform network and disk I/O activities simultaneously.
(b. ) A weather modeling system with a very large number of computationally intensive threads which frequently coordinate with one another.
2. (30 points) Using the execlp, fork, kill, and waitpid functions described below, write psuedo code for a program which performs the actions described below. You can assume that execlp("program") will execute "program", fork() will fork a new process and return the ID of the child to the parent or 0 to the child process, kill(pid) will kill the process with ID=pid, and waitpid(pid) will wait for the process with ID=pid to complete before returning.
The parent process starts a child process. The child process starts two additional "grandchild" processes. The first and second grandchild processes each execute a new program: "grandchild_1" and "grandchild_2" respectively. The original child process waits for grandchild_1 to complete, and then kills grandchild_2. The original parent process waits for the child to complete, and then prints a message saying "Children Finished!".
3. (10 points) On a quad core system, how many processes can be in the ready state at the same time? What about in the running state?
4. (10 points) Several students are waiting to use a microwave. Alice wants to heat her pizza (90 seconds), Bob has soup (60 seconds), and Charlie needs to dethaw his frozen dinner (180 seconds). In what order do you think they should heat their food? Why? What happens to Charlie if class lets out and new students keep appearing with containers of soup to heat?
5. (30 points) For the following mix of jobs, lengths, and arrival times, determine the scheduling order and average wait time for the First Come First Served (FCFS), Round Robin (RR), and Shortest Job First (SJF) schedulers. Assume all times are in msec. For the RR scheduler, use a 5 msec time slice and a 0 msec context switch cost; assume that when new tasks arrive they are placed at the head of the queue for jobs waiting to be scheduled.
Fill in the following table with the time of completion and time spent waiting for each task. Use the reported average wait times to check your answer.
Time of Completion | Wait Time | |||||||
Job | Arrival | Length | FCFS | RR | SJF | FCFS | RR | SJF |
A | 0 | 40 | ||||||
B | 5 | 15 | ||||||
C | 20 | 25 | ||||||
D | 40 | 20 | ||||||
Average Wait Time: | 27.5 | 36.25 | 26.25 |
6. (10 points) Consider the "Too Much Milk" problem discussed in Lecture 8. Suppose that you use a similar solution as described in the lecture, but that whenever you aren't out buying milk you or your roommate should be doing homework. If the act of buying milk is very slow, then why would the following algorithm be inefficient? How could you rewrite the algorithm to spend less time waiting and more time doing homework?
while(graduated == false) { Lock.Acquire(); if(noMilk) { buyMilk(); // this could take a while noMilk = false; } Lock.Release(); doHomeworkProblem(); }(assume that occassionally noMilk is set to true by the doHomeworkProblem() function)