1. If you can only run one program at a time, is it still useful to have an operating system? Why or why not? 2. Name three major resources controlled by an operating system. 3. Which of the following machine instructions should be privileged? Explain why. a) Set value of timer b) Read system clock c) Clear memory d) Turn off interrupts e) Switch from user to supervisor mode 4. How do I/O-bound and CPU-bound programs differ? 5. What is a context switch? Why is it important that context switching be fast? 6. What is the time quantum used for? How should the time quantum be related to the context switch time? 7. What is an advantage of a large scheduling quantum? What is a disadvantage? 8. The kernel keeps a record for each process, called the Process Control Block (PCB). When a process is not running, its PCB contains the information that is necessary to restart the process on the CPU. List two pieces of information that the PCB must have. 9. How does creating a thread differ from creating a process? How does context switching for threads differ from context switching for processes. 10. What are the different states a process can be in? What are the possible transitions between states? (Draw a picture.) What events can cause each of those transitions to happen? 11.Give four causes for a running process to relinquish the CPU. 12. List three things that a running process might do that would cause the scheduler not to move it to the ready state when it stops running. 13. Use process states to describe the difference between the two function calls Sleep(0) and Sleep(1). 14. Use process states to explain the difference between busy waiting and blocking. 14. What is the difference between a preemptive scheduler and a non­preemptive scheduler? 15.Each of the following is a component of the scheduler. Briefly explain what each component does. a.Enqueuer b.Ready list c.Dispatcher d.Context switcher 16. Here is an easy-to-implement approach to scheduling that works pretty well: put the I/O- bound processes at the top of the priority list and the CPU-bound processes at the bottom. What makes this approach work? 17. Here are two possible policies for a scheduler. Policy A: Scheduling decisions are made whenever a process terminates, a quantum expires, or a process blocks. Policy B: Scheduling decisions are made whenever a process terminates, a quantum expires, a process blocks, or whenever a process unblocks (becomes ready). Explain how Policy B can help prevent a situation of process starvation that Policy A cannot prevent. (Hint: Blocking on a resource.) 18. For Round Robin scheduling, what is the effect of increasing the time quantum to an arbitrarily large number? Explain your answer. 19. For the next 10 problems, use the following process load description (this problem comes from the author's web site, so you can get the answers there): Process Service Time Priority 0 150 2 1 30 3 2 130 5 3 80 1 4 90 4 a) Using FCFS, what is the average wait time for the example process set? b) Using FCFS, what is the average turnaround time for the example process set? c) Using SJN, what is the average wait time for the example process set? d) Using SJN, what is the average turnaround time for the example process set? e) Using priority scheduling, what is the average wait time for the example process set? f) Using priority scheduling, what is the average turnaround time for the example process set? g) Using RR scheduling with a time quantum of 40 and no scheduling overhead, what is the average wait time for the example process set? h) Using RR scheduling with a time quantum of 40 and no scheduling overhead, what is the average turnaround time for the example process set? i) Using RR scheduling with a time quantum of 40 and 10 units of time for scheduling overhead (dispatching, context switching, etc.) what is the average wait time for the example process set? j) Using RR scheduling with a time quantum of 40 and 10 units of time for scheduling overhead (dispatching, context switching, etc.) what is the average turnaround time for the example process set? For each of the FCFS, SJN, nonpreemptive priority scheduling, preemptive priority scheduling, and RR (with a time quantum of 40) scheduling policies, create a Gantt chart illustrating the execution of the processes in the example process set. 20. A scheduler uses a prioritized round­robin scheduling policy. New processes are assigned an initial quantum of length q. Whenever a process uses its entire quantum without blocking, its new quantum is set to twice its current quantum. If a process blocks before its quantum expires, its new quantum is reset to q. For the purposes of this question, assume that every process requires a finite total amount of CPU time. a. Suppose the scheduler gives higher priority to processes that have larger quanta. Is starvation possible in this system, i.e., is it possible that a process will never complete because it is neglected by the scheduler? b. Suppose instead that the scheduler gives higher priority to processes that have smaller quanta. Is starvation possible in this system? 21. a) In general, blocking is better than busy waiting. Explain why. b) If it is known in advance that a wait will be very short, then busy waiting can be better than blocking. Explain why. 22. What is a race condition? 23. What is a critical section? 24. Briefly describe three ways that the critical section problem can be solved. 24. Suppose that an operating system has the policy that scheduling decisions are only made whenever a process terminates or a running process blocks. How does this policy affect the problem of critical sections? 25. The following code outlines a certain kind of synchronization pattern. In what way are the two threads synchronized? How might this pattern get used? int main() { //thread function prototypes DWORD WINAPI thread1(LPVOID); DWORD WINAPI thread2(LPVOID); semaphore = CreateSemaphore(NULL, 0, 1, NULL); // not signaled CreateThread(NULL, 0, thread1, 0, 0, NULL); CreateThread(NULL, 0, thread2, 0, 0, NULL); while(1){ Sleep(1000); } return 0; }//main DWORD WINAPI thread1(LPVOID threadParam) { for (int i = 0; i < N; i++;) { < do a calculation > ReleaseSemaphore(semaphore, 1, NULL); < do a long calculation > ReleaseSemaphore(semaphore, 1, NULL); < do another long calculation > } return 0; }//thread1 DWORD WINAPI thread2(LPVOID threadParam) { while(1) { WaitForSingleObject(semaphore, INFINITE); < do a very short calculation > } return 0; }//thread2 26. The following code outlines a certain kind of synchronization pattern. In what way are the two threads synchronized? How might this pattern get used? int main() { //thread function prototypes DWORD WINAPI thread1(LPVOID); DWORD WINAPI thread2(LPVOID); semaphore1 = CreateSemaphore(NULL, 0, 1, NULL); // not signaled semaphore2 = CreateSemaphore(NULL, 0, 1, NULL); // not signaled CreateThread(NULL, 0, thread1, 0, 0, NULL); CreateThread(NULL, 0, thread2, 0, 0, NULL); while(1){ Sleep(1000); } return 0; }//main DWORD WINAPI thread1(LPVOID threadParam) { for (int i = 0; i < N; i++;) { ReleaseSemaphore(semaphore2, 1, NULL); WaitForSingleObject(semaphore1, INFINITE); < do first calculation > ReleaseSemaphore(semaphore2, 1, NULL); WaitForSingleObject(semaphore1, INFINITE); < do second calculation > } return 0; }//thread1 DWORD WINAPI thread2(LPVOID threadParam) { while(1) { ReleaseSemaphore(semaphore1, 1, NULL); WaitForSingleObject(semaphore2, INFINITE); < do a calculation > } return 0; }//thread2 27. In the last example, what would happen if the second ReleaseSemaphore(semaphore2, 1, NULL); in Thread1 was deleted? 28. The following code outlines a certain kind of synchronization pattern. In what way are the two threads synchronized? How might this pattern get used? int main() { //thread function prototypes DWORD WINAPI thread1(LPVOID); DWORD WINAPI thread2(LPVOID); semaphore1 = CreateSemaphore(NULL, 1, 1, NULL); // signaled semaphore2 = CreateSemaphore(NULL, 0, 1, NULL); // not signaled CreateThread(NULL, 0, thread1, 0, 0, NULL); CreateThread(NULL, 0, thread2, 0, 0, NULL); while(1){ Sleep(1000); } return 0; }//main DWORD WINAPI thread1(LPVOID threadParam) { for (int i = 0; i < N; i++;) { WaitForSingleObject(semaphore1, INFINITE); < do first calculation > ReleaseSemaphore(semaphore2, 1, NULL); WaitForSingleObject(semaphore1, INFINITE); < do second calculation > ReleaseSemaphore(semaphore2, 1, NULL); } return 0; }//thread1 DWORD WINAPI thread2(LPVOID threadParam) { while(1) { WaitForSingleObject(semaphore2, INFINITE); < do a calculation > ReleaseSemaphore(semaphore1, 1, NULL); } return 0; }//thread2