Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

13 Problems with Solution key, 1st Exam on Operating Systems | CS 1550, Exams of Computer Science

Material Type: Exam; Class: INTRO TO OPERATING SYSTEMS; Subject: Computer Science; University: University of Pittsburgh; Term: Spring 2005;

Typology: Exams

Pre 2010

Uploaded on 09/02/2009

koofers-user-nto-1
koofers-user-nto-1 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 1550 – Spring 2005 -- 1st Exam
Profs. José Carlos Brustoloni and Daniel Mossé
1. How can a program transition:
a. (3 points) from user mode to kernel mode voluntarily?
System call
b. (3 points) from user mode to kernel mode involuntarily?
Interrupt, page fault, other hardware exception
c. (3 points) from kernel mode to user mode?
Return from system call or interrupt
2. What is the most important parameter to optimize in an operating system for:
a. (3 points) interactive applications?
Response time
b. (3 points) supercomputing?
Throughput
3. (3 points) When a _user-level_ thread performs a blocking I/O system call, all threads in the
same process are blocked.
4.
a. (7 points) Among the following items: address space, stack, register values, open file
descriptors, program counter, heap, processor state, and text, which ones may differ
among threads in the same process?
Stack, register values, program counter, processor state
b. (3 points)Among those items that may differ, which ones can be corrupted by a thread
of a different process?
None
5. Let (x, y, z) mean that process x arrives at time y and needs z time units of processing time:
(A, 0, 15), (B, 0.1, 3), (C, 2, 2), (D, 5, 1)
For each of the following scheduling algorithms, please give (a) the resulting schedule, and (b)
the average turnaround time (i.e., time between each process’s arrival and completion):
a. (3 points) FIFO
Schedule: A(0,15), B(15,18), C(18,20), D(20,21)
Turnaround times: A = 15
B = 18 – 0.1 = 17.9
C = 20 – 2 = 18
D = 21 – 5 = 16
Ave. = 16.725
b. (3 points) SJF (Shortest Job First)
Schedule: A(0,15), D(15,16), C(16,18), B(18,21)
Turnaround times: A = 15
B = 21 – 0.1 = 20.9
C = 18 – 2 = 16
D = 16 – 5 = 11
Ave. = 15.725
pf3
pf4
pf5

Partial preview of the text

Download 13 Problems with Solution key, 1st Exam on Operating Systems | CS 1550 and more Exams Computer Science in PDF only on Docsity!

CS 1550 – Spring 2005 -- 1

st

Exam

Profs. José Carlos Brustoloni and Daniel Mossé

  1. How can a program transition: a. (3 points) from user mode to kernel mode voluntarily? System call b. (3 points) from user mode to kernel mode involuntarily? Interrupt, page fault, other hardware exception c. (3 points) from kernel mode to user mode? Return from system call or interrupt
  2. What is the most important parameter to optimize in an operating system for: a. (3 points) interactive applications? Response time b. (3 points) supercomputing? Throughput
  3. (3 points) When a _ user-level _ thread performs a blocking I/O system call, all threads in the same process are blocked.
  4. a. (7 points) Among the following items: address space, stack, register values, open file descriptors, program counter, heap, processor state, and text, which ones may differ among threads in the same process? Stack, register values, program counter, processor state b. (3 points) Among those items that may differ, which ones can be corrupted by a thread of a different process? None
  5. Let (x, y, z) mean that process x arrives at time y and needs z time units of processing time: (A, 0, 15), (B, 0.1, 3), (C, 2, 2), (D, 5, 1) For each of the following scheduling algorithms, please give (a) the resulting schedule, and (b) the average turnaround time (i.e., time between each process’s arrival and completion): a. (3 points) FIFO Schedule: A(0,15), B(15,18), C(18,20), D(20,21) Turnaround times: A = 15 B = 18 – 0.1 = 17. C = 20 – 2 = 18 D = 21 – 5 = 16 Ave. = 16. b. (3 points) SJF (Shortest Job First) Schedule: A(0,15), D(15,16), C(16,18), B(18,21) Turnaround times: A = 15 B = 21 – 0.1 = 20. C = 18 – 2 = 16 D = 16 – 5 = 11 Ave. = 15.

c. (3 points) Shortest Remaining Time First (assume perfect predictor of remaining time, arriving process can preempt immediately, quota = 1) Schedule: A(0,0.1), B(0.1,3.1), C(3.1,5.1), D(5.1,6.1), A(6.1,21) Turnaround times: A = 21 B = 3.1 – 0.1 = 3 C = 5.1 – 2 = 3. D = 6.1 – 5 = 1. Ave. = 7. Another solution if we consider the quota: Schedule:a. A(0,1), B(1,4), C(4,6), D(6,7), A(7,21) Turnaround times: A = 21 B = 4 – 0.1 = 3. C = 6 – 2 = 4 D = 7 – 5 = 2 Ave. = 7. b. A(0,1), B(1,2), C(2,4), B(4,5), D(5,6), B(6,7), A(7,21) c. A(0,1), B(1,2), C(2,4), B(4,6), D(6,7), A(7,21) Average time is still 7 .725. d. (3 points) Round robin (quota = 2) Assuming C gets into the ready queue ahead of A at time = 2: Schedule: A(0,2), B(2,4), C(4,6), A(6,8), B(8,9), D(9,10), A(10,21) Turnaround times: A = 21 B = 9 – 0.1 = 8. C = 6 – 2 = 4 D = 10 – 5 = 5 Ave. = 9. Assuming C gets into the ready queue behind A at time = 2: Schedule: A(0,2), B(2,4), A(4,6), C(6,8), B(8,9), D(9,10), A(10,21) Turnaround times: A = 21 B = 9 – 0.1 = 8. C = 8 – 2 = 6 D = 10 – 5 = 5 Ave. = 10.

  1. (3 points) Consider a system with two or more devices or processes that perform operations at the same time over and over again. If errors may result depending on the exact sequence of the operations, the system has: a. Deadlock b. Starvation c. A race condition d. Busy waiting c. A race condition
  2. (4 points) Two mechanisms that can be used to avoid the error in question 6 are __ semaphores_ _ and __ monitors __.
  1. (6 points) Show pseudo-code of how counting semaphores can be implemented using binary semaphores. typedef struct { bin_semaphore M; bin_semaphore B; int count; } count_semaphore; void count_initialize (count_semaphore *s) { s-> M = 1; s->B = 0; s->count = 0; } void count_down (count_semaphore *s) { bin_down(s->M); s->count--; if (s->count >= 0) { bin_up(s->M); } else { bin_up(s->M); bin_down(s->B); } } void count_up (count_semaphore *s) { bin_down (s->M); s->count++; if (s->count > 0) { bin_up(s->M); } else { bin_up(s->B); bin_up(s->M); } }
  2. (5 points) Explain how spooling prevents deadlock. What necessary condition for deadlock does spooling remove? Instead of writing directly to a printer or other shared output device, processes write to separate output files on disk, a resource for which contention is much less likely. A single process, the printer daemon, then reads other processes’ output files from disk and actually sends them to the printer sequentially. Because only one process actually writes to the printer, there is no mutual exclusion, one of the necessary conditions for deadlock.
  1. (5 points) Give an example of how the use of semaphores can lead to deadlock. Explain how you can, in general, prevent deadlock when using semaphores. What necessary condition for deadlock are you preventing? Assume that you can use only regular semaphore primitives (i.e., down, up). Suppose there are two semaphores, A and B. If process 1 does: down(A); down(B), while process 2 does: down(B); down(A), deadlock may result if one of the processes preempts the other process when the latter has performed only one of the down operations. Deadlock can be prevented by assigning an arbitrary order to the semaphores (e.g., based on their addresses), and performing a down operation on a semaphore only if the process does not currently hold any semaphore with lower order (e.g., address). When a process needs to perform a down operation that would be precluded by this rule, the process first performs an up operation on the lower-order semaphores, and then performs down operations on the required semaphores according to their order. This scheme eliminates circular wait, a necessary condition for deadlock.
  1. (5 points) Given the following system with four processes 1, .., 4 and four resources A, .., D, for what values of x is the system in a safe state? Show how you reached your conclusion. Hint: Use the Banker’s algorithm. Allocation Maximum Available A B C D A B C D A B C D Process 1 3 2 3 0 3 3 x 5 0 1 2 0 Process 2 1 1 2 2 1 2 4 2 Process 3 1 0 0 3 2 1 0 3 Process 4 0 1 0 0 2 2 2 1 Process 2 can complete, making Available = (1 2 4 2) Process 3 can then complete, making Available = (2 2 4 5) Process 4 can then compete, making Available = (2 3 4 5) Process 1’s maximum C allocation cannot be less than what it initially has: x >= 3. On the other hand, if Process 1 can complete, then Process 1’s maximum C allocation cannot be greater than its initial allocation plus what is available after all other processes complete: x <= 3 + 4 = 7. Thus, 3 <= x <= 7.