Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views3 pages

Quiz 3

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

1.What is the meaning of the term busy waiting?

What other kinds of waiting are there in an


operating system? Can busy waiting be avoided altogether? Explain your answer.
Answer: Busy waiting means that a process is waiting for a condition to be satisfied in a tight
loop without relinquishing the processor. Alternatively, a process could wait by relinquishing the
processor, and block on a condition and wait to be awakened at some appropriate time in the
future. Busy waiting can be avoided but incurs the overhead associated with putting a process
to sleep and having to wake it up when the appropriate program state is reached.

2. Why do Solaris, Linux, and Windows 2000 use spinlocks as a synchronization mechanism
only on multiprocessor systems and not on single processor systems?
Answer: Spinlocks are only used as a synchronization mechanism on multiprocessor systems
in Solaris, Linux, and Windows 2000. This is because the condition that would break a process
or thread out of spinlock could only be attained by executing a distinct process and thus not
appropriate for single processor systems. If the process does not give up the processor then
other processes would not get the chance to set the program condition required for the first
process pr thread to make progress. Whereas, in multi-processor systems other processes can
run and get executed on other processors and in process they change the program state and
release the first process or thread from the spinlock. Thus, Solaris, Linux, and Windows 2000
use spinlocks as a synchronization mechanism only on multiprocessor systems and not on
single processor systems.

3.Suppose that the following processes arrive for execution at the times indicated. Each process
will run for the amount of time listed. In answering the questions, use nonpreemptive
scheduling, and base all the decisions on the information you have at the time the decision must
be made.

a.What is the average turnaround time for these processes with the FCFS scheduling
algorithm?
b. What is the average turnaround time for these processes with the SJF scheduling algorithm?
c. The SJF algorithm is supposed to improve performance, but notice that we choose to run
process P1 at time 0 because we did not know that two shorter processes would arrive soon.
Compute what the average turnaround time will be if the CPU is left idle for the first 1 unit and
then SJF scheduling is used. Remember that processes P1 and P2 are waiting during this idle
time, so their waiting time may increase. The algorithm could be known as future-knowledge
Scheduling
a.Solution: Average turnaround for these processes: ( 8 + (12 - 0.4) + (13 - 1)) / 3 = 10.53
b.Solution: Average turnaround for these processes: ( 8 + (9 - 1) + (13 – 0.4)) / 3 = 9.53
c.Solution: CPU is left idle: Average turnaround for these processes: ((2 - 1) + ( 6 – 0.4 ) + ( 14
- 0)) / 3 = 6.87
4. A CPU scheduling algorithm determines an order for the execution of its scheduled
processes. Given 'n' processes to be scheduled on one processor, how many possible different
schedules are there?
Answer: Number of possible schedules can be calculated as follows:
- The first process can be selected in n ways.
- The second process can be selected in (n-1) ways.
- The third process can be selected in (n-2) ways.
- Similarly, the kth process can be selected in (n-k+1) ways.
- The last process can be selected in 1 way.
Therefore, the total number of possible schedules = n x (n-1) x (n-2) x ... x 2 x 1 = n!

5. What are three requirements of any solution to the critical sections problem? Why are
the requirements needed?
Answer: 1. Mutual Exclusion - If process P, is executing in its critical
section, then no other processes can be executing in their critical sections
2. Progress - If no process is executing in its critical section and
there exist some processes that wish to enter their critical section, then the selection of the
processes that will enter the critical section next cannot be postponed indefinitely
3. Bounded Waiting - A bound must exist on the number of
times that other processes are allowed to enter their critical sections after a process has made a
request to enter its critical section and before that request is granted
• Assume that each process executes at a nonzero speed
• No assumption concerning relative speed of the n processes

6. What is deadlock? What is starvation? How do they differ from each other?

Answer:Deadlock-two or more processes are waiting indefinitely for an event that can be
caused by only one of the waiting processes
Let S and Q be two semaphores initialized to 1
Po P1
wait (S); wait (Q);
wait (Q); wait (S);
…. ….
signal (S); signal (Q);
signal (Q); signal (S);

Starvation-indefinite blocking:
A process may never be removed from the semaphore queue in which it is suspended.
Difference between Deadlock and Starvation:

Deadlock Starvation
All processes keep waiting for each other to High priority processes keep executing
complete and none get executed and low priority processes are blocked

Resources are blocked by the processes Resources are continuously utilized by


high priority processes

Necessary conditions Mutual Exclusion, Hold Priorities are assigned to the processes
and Wait, No preemption, Circular Wait

Also known as Circular wait Also known as lived lock

It can be prevented by avoiding the necessary It can be prevented by Aging


conditions for deadlock

You might also like