You are on page 1of 4

1

Answers to Final Examination of Operating Systems


2005/01/11 (Tue.)

1. (5%) What is throughput?
The number of processes completed per time unit.

2. (10%) Explain the four necessary conditions for a deadlock.
Mutual exclusion, Hold and wait, No preemption, Circular wait.

3. (10%) What is the concept of thread pools? And what are its benefits?

(a) Unlimited threads could exhaust system resources. The general idea behind a thread pool is to
create a number of threads at a process startup and place them into a pool. When a server
receives a request, it awakens a thread from this pool, and passing it the request to service. Once
the thread completes its service, it returns to the pool awaiting more work. If the pool contains no
available thread, the server waits until one becomes free.
(b)
i. It is usually faster to service a request with an existing thread than waiting to create a
thread.
ii. A thread pool limits the number of threads that exist at any one point, preventing from
exhausting system resources.
4. (10%) What are two differences between user-level threads and kernel-level threads?

(a) User-level threads are unknown by the kernel, whereas the kernel is aware of kernel threads.
(b) User-level threads are scheduled by the thread library and the kernel schedules kernel-level
threads.
5. (20%) Consider the following set of processes, with the length of the CPU-burst time given in
milliseconds:
Process Burst Time Priority
P
1
10 3
P
2
1 1
P
3
2 3
P
4
1 4
P
5
5 2
The processes are assumed to have arrived in the order P
1
, P
2
, P
3
, P
4
, P
5
, all at time 0.
(a) Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a
nonpreemptive priority (a smaller priority number implies a higher priority), and RR
(quantum=1) scheduling.
(b) What is the turnaround time of each process for each of the scheduling algorithms in part
a?
(c) What is the waiting time of each process for each of scheduling algorithms in part a?
(d) Which of the schedules in part a results in the minimal average waiting time (over all
processes)?

(a) The four Gantt charts are


(b) Turnaround time
FCFS RR SJ F Priority
P
1
10 19 19 16
P
2
11 2 1 1
P
3
13 7 4 18
P
4
14 4 2 19
P
5
19 14 9 6

(c) Waiting time
FCFS RR SJ F Priority
P
1
0 9 9 6
P
2
10 1 0 0
P
3
11 5 2 16
P
4
13 3 1 18
P
5
14 9 4 1

(d) Shortest J ob First
6. (10%) Explain why spinlocks are not appropriate for uniprocessor systems yet may be suitable
for multiprocessor systems.
In a uniprocessor system, if a thread of control uses a spinlock, and begins spinning on it because the
lock is already held, the lock must be held by a process that is not executing. Spinning on the lock is
thus a huge waste of time because the process spins through the loop continuously looking at a
semaphore variable that cannot change value until the spinning process gives up the CPU and
permits the process holding the lock to execute again, thus giving it a chance to finish using the lock
2
3
and to release it. In a multiprocessor system, a process spins could be unlocked by the process that
holds the lock running on another processor
7. (15%) Consider the following snapshot of a system:
Allocation Max Available
ABCD ABCD ABCD
P
0
0 0 1 2 0 0 1 2 1 5 2 0
P
1
1 0 0 0 1 7 5 0
P
2
1 3 5 4 2 3 5 6
P
3
0 6 3 2 0 6 5 2
P
4
0 0 1 4 0 6 5 6

Answer the following questions using the bankers algorithm:
(a) What is the content of the matrix Need?
(b) Is the system in a safe state?
(c) If a request from process P
1
arrives for (0, 4, 2, 0), can the request be granted
immediately?

(a) P
0
: 0 0 0 0, P
1
: 0 7 5 0, P
2
: 1 0 0 2, P
3
: 0 0 2 0, P
4
: 0 6 4 2
(b) Yes.
(c) Yes.

8. (10%) Consider the following resource-allocation policy. Requests and releases for resources
are allowed at any time. If a request for resources cannot be satisfied because the resources are
not available, then we check any processes that are blocked, waiting for resources. If they have
the desired resources, then these resources are taken away from them and are given to the
requesting process. The vector of resources for which the waiting process is waiting is
increased to include the resources that were taken away.
For example, consider a system with three resource types and the vector Available initialized to
(4,2,2). If process P
0
asks for (2,2,1), it gets them. If P
1
asks for (1,0,1), it gets them. Then, if P
0

asks for (0,0,1), it is blocked (resource not available). If P
2
now asks for (2,0,0), it gets the
available one (1,0,0) and one that was allocated to P
0
(since P
0
is blocked). P
0
s Allocation
vector goes down to (1,2,1), and its Need vector goes up to (1,0,1).
(a) Can deadlock occur? If so, give an example.
If not, which necessary condition cannot occur?
(b) Can indefinite blocking occur?

(a) Deadlock cannot occur because preemption exists.
(b) Yes. A process may never acquire all the resources it needs if they are continuously preempted
4
by a series of requests.
9. (10%) Consider the following 3-process concurrent program which uses semaphores S1, S2,
and S3. The semaphore operation, which are sometimes called wait and signal, are
denoted here with the classical notation of P and V.
Process 1 Process 2 Process 3
L1:P(S3); L2:P(S1); L3:P(S2);
print(T); print(U); print(B);
V(S2); V(S3); V(S1);
goto L1; gotoL2 goto L3;
a) Are there initial values that can be given to the semaphores so that the processes
cooperate to print the string BUTBUTBUTBU? If so, give the initial values (tell which
value is to be used for which semaphore) and explain how the string is printed.
b) Suppose the initial values are S1=0, S2=0, S3=0. Is it possible for the processes to
cooperate to produce a string that begins with BBTTUTT? Explain your answer.

(a) Yes. S1 =0, S2 =1, S3 =0
(b) No.

You might also like