Академический Документы
Профессиональный Документы
Культура Документы
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.
a) Using the SJF method, compute the completion times of the above jobs,
average turn around time and average waiting time.
b) 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.
c) 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.
5 3 4 5
A D B C
0 5 8 12 17
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
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.
5 3 4 5
A D B C
0 5 8 12 17
Aboe gantt chart is some as the SJF scheduling Gantt chart. Then all the results
will be same.
c) Gantt Chart:
A B C D A B C D A C
0 2 4 6 8 10 12 14 15 16
17
Q3:) What will be the number of page faults for the algorithms (FIFO, LRU and
Optimal) for the following page reference string:
1,2,3,3,5,1,2,2,6,2,1,5,7,6,3
1 , 2 , 3 , 3 , 5 , 1, 2 , 2 , 6 , 2 , 1 , 5 , 7 , 6 , 3
1)FIFO algorithms:
Reference Strings
1 2 3 3 5 1 2 2 6 2 1 5 7 6 3
1 1 1 1 6 6 6 6
2 2 2 2 2 1 1
3 3 3 3 7 7
5 5 5 5 3
No. of
Page fault
1 2 3 4 5 6 7 8
Total number of page fault = 8
2) LRU algorithm:
Reference string
Page frame
1 2 3 3 5 1 2 2 6 2 1 5 7 6 3
1 1 1 1 1 1 1 3
2 2 2 2 2 6 6
3 3 6 7 7 7
5 5 5 5 5
1 2 3 4 5 6 7 8
Total number of page fault = 8.
3) Optimal Algorithm:
Reference string
Page frame
1 2 3 3 5 1 2 2 6 2 1 5 7 6 3
1 1 1 1 1 1 3
2 2 2 2 7 6
3 3 6 7 7
5 5 5 5
1 2 3 4 5 6 7
Q4) There is a total of 15 units of R1 (resource 1) and 7 units of R2 and the system is
in the following state (again call it S0):
a) Show that the above state is a safe state. You must come up with a complete
sequence of jobs.
Now system state are in safe because we can make more request according to the Need
column of above table.
Algorithm:
Let request i be the request vector for process Ri. If Request i[j] = k , the process
Pi wants K instance of resource type Rj. When a request for resources is made by
process Pi, the following actions are taken:
b) If the system is in state so, should a request of (0,2) units by p2 be granted? You must
give a sequence.
d) If the system is in state so, should a request of (2,0) units by p2 be grated? You
must give a sequence.
Request(P2) = (2, 0)
Using above algorithm
Request (P2) ≤Need (P2)
(2,0) ! ≤Need (P2) = (1,5)
So, error will be printed. Request is granted.
e) If the system is in state so, should a request of (1,1) units by P2 be granted? You
must give a sequence.
Q5)
a) List the security attacks that cannot be prevented by encryption.
• choosen – plaintext – same as known – plaintext attack, but the analyst gets a
to choose the known plaintext.
• Cyphertext – only – Attempt to recover plaintext from encrypted text sent in
the message.
• Known – plaintext – Attempt to discover the key used when the analyst has
access to the plaintext of the encrypted message.
• Brute force.
• Differential cryptoanalysis.
• Linear cruptoanalysis.
• Passive – An attack such as listening to communications then attacking the
encryption shceme off line may be done.
• Active – A common attack of this type is the main in the middle attack.
During this attack the attacker may try to convience the victim that they are
communicating with another party when they are really communicating with
the attacker. The attacker may as use the attack to gain passwords or other
vital information.
• Dictonary attack – A means attacking a system to determine passwords from
hashed or encrypted passwords.
Q6:)
Discuss in detail the Process management, Memory management, I/O and File
management and Security and Protection in LINUX Operating System.
Memory Management:
Memory is the most expensive part in the computer system. Memory is a large array of
words or bytes, each with its own address. Interaction is achieved through a sequence of
reads/writes of specific memory address. The cpu fetches from a stores in memory.
There are various algorithms that depend on the particular situations to manage the
memory. Selection of a memory management scheme for a specific system depends upon many
factors, but especially upon the hardware design of the system. Each algorithm requires its own
hardware support.
The Operating System is responsible for the following activities in connection with
Memory Management.
• Keep track of which parts of memory are currently being used and by
whom.
• Decide which processes are to be loaded into memory when memory
space becomes available.
• Allocate and deallocate memory space as needed.
A Operating System for a security control system. It consist of a number of programs. One of
these programs would gain control of the Operating system when it is powered o and initialize the
system. The first task of this initialize program would be to reset the hardware sensors and
alarms. Once the hardware initialization was complete the Operating System would enter a
continual monitoring routine of all the input sensors. If the state of any input sensor is changed it
would branch to an alarm generation routine.
The various processes in an Operating System must be protected from each others
activities. For that purpose, various mechanisms which can be used to ensure that the files,
memory segment, cpu and other resources can be operated on only by those processes that have
gained proper authorization from the Operating System.