|
|
IGNOU > IGNOU Assignments > MCA > MCA 2008 Assignments > Operating Systems Programming
IGNOU MCA Assignments
Question 1: Write a monitor solution to the Readers/Writers problem.
Ans:
readers – writers : monitor
begin
readercout : interger;
busy : Boolean;
OKtoread , OKtowrite : condition;
procedure startread;
begin
if busy then OKtoread.wait;
readercount :=readercount + 1;
OKtoread.signal;
(*Once one reader can start, they all can *)
end startend;
procedure endread;
begin
readercount : = readercount – 1;
if readercount =0 then OKtowrite.signal;
end endread;
procedure startwrite;
begin
if busy OR readercout !=0 then OKtowrite.wait;
busy : = true;
end startwrite ;
procedure endwrite;
begin
busy:=false;
if OKtoread.queue then OKtoread.signal else OKtowrite.signal;
end OKtowrite.sigal;
end endwrite;
begin(*initialization*)
readercount :=0;
busy: false;
end;
end readers - writers;
The above code gives a solution to the readers priority problem using monitors. For proper synchronization reader processes must call the startread procedure before accessing the file and call the endread when the read is finished. Likewise, writer processes must call startwrite before modifying the file and call endwrite when the write is finished. The monitor users the Boolean variables busy to indicate whether a writer is active and readercount to keep track of the number of active readers.
On invoking startread, a reader process is blocked and placed in the queue of the OKtoread condition variable if busy is true Otherwise, the reader proceeds and performs the following. The process increments the readercount, and activated a waiting reader, if present, thought the OKtoread.signal operation. On the completion of access, a reader invokes endread, where readercount is decremented. When there are no active readers, the last exiting reader process performs the Oktowrite.signal operation to activate any waiting writer.
A writer, on invoking startwrite, proceeds only when no other writer or readers are active. The process sets busy to true to indicate that a writer is active. On completion of the access, a writer invokes the endwrite procedure. The endwrite procedure sets busy to false, indicating that no writer is active, and checks the OKtoread queue for the presence of waiting readers. If there is a waiting reader, the exiting writer queue. If a reader otherwise it signals the writer queue. If a reader is activated in endwrite procedure, it increments the readercount and executes the OKtoread signal, thereby activating the next waiting reader in the queue. This process continues until all the waiting readers have been activated, during which processes trying to enter the monitor are blocked and join the monitor’s entry queue. But, after all the readers waiting on the OKtoread condition have been signed, any newely arrived readers will again access to the monitor before any waiting writers. In summary, the readers priority monitor, while not permitting a new writer to start when there is a reader waiting, permits any number of readers to proceed, as long as there is at least one active reader.
Question 2: Consider the following jobs:
| Job # |
Arrival time |
Run time |
| A |
0 |
5 |
| B |
2 |
4 |
| C |
3 |
5 |
| D |
5 |
3 |
- Using the SJF method, compute the completion times of the above jobs, average turn around time and average waiting time.
- Using the SRTF (Shortest Remaining Time first) method, compute the the completion times of the above jobs, the average turn around time and the average waiting time. Note that SRTF is SJF with preemption. Completion time - arrival time = turnaround time
- Using the Round Robin method (with Quantum = 2), compute the completion times of the above jobs and the average waiting time.
Ans:
a) Using the SJF (shortest-job-first shcheduling) alogirithm. We would schedule these processes according to the following Gantt chart.
Completion time for process A = 5
Completion time for process B =12
Completion time for process c = 17
Completion time for process D = 8
Turn around time = T(completion) – T(Arrival)
Turnaround time for process A = 5-0 = 5 mr
Turnaround time for process B = 12-2 = 10 mr
Turnaround time for process A = 17 – 3 = 14 mr
Turnaround time for process A = 8 – 5 = 3 mr
Total Turnaround time = 5+ 10 + 14 + 3 = 32
Average turnaround time = 32/7 = 8.00 mr
Average waiting time :
Waiting time for process A = 0 mr
Waiting time for process B = 6 mr
Waiting time for process C = 9 mr
Waiting time for process D = 0 mr
Total waiting time = 0+6+9+0 = 15
Average waiting time = 15/4 = 3.75 mr
b) A preemptive SJF algorithm will pre-empt the currently executing process, whereas a non preemptive SJF algorithm will allow the currently running process to finish its CPU burst. Preemptive SJF scheduling is sometimes called shortest remaining time – first scheduling.
It is the processes arrive at the ready queue at the times shown and need the indicated burst times, then the resulting preemptive SJF (SRTF) schedule is as depicted in the following Gantt chart.
Aboe gantt chart is some as the SJF scheduling Gantt chart. Then all the results will be same.
c) Gantt Chart:
| 0 |
2 |
4 |
6 |
8 |
10 |
12 |
14 |
15 |
16 |
17 |
Completion time for A = 16
Completion time for B = 12
Completion time for C = 17
Completion time for D =15
Average waiting time:
Waiting time for process A = 0 +6+5 = 11 mr
Waiting time for process B = 0+6 = 6 mr
Waiting time for process C = 1+6+4 = 11 mr
Waiting time for process D = 1+6 = 7 mr
Total waiting time = 11+6+11+7 = 35
Average waiting time = 35/4 = 8.75 mr.
  
|
|