Вы находитесь на странице: 1из 9

Q1:) 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.

Q2:) Consider the following jobs:

Job # Arrival time Run time


A 0 5
B 2 4
C 3 5
D 5 3

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.

Completion time - arrival time = turnaround time

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

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.
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

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.

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

for a memory with 4 frames?

Ans:) Page reference string:

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

Total number of page fault = 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):

Process Max Allocation


R1 R1 R2
R2
P0 4 2 2 2
P1 5 7 4 1
P2 4 6 3 1
P3 6 4 3 2

a) Show that the above state is a safe state. You must come up with a complete
sequence of jobs.

b) If the system is in state S0, should a request of (2,0) units by P2 be granted?


You must give a sequence.

c) If the system is in state S0, should a request of (0,2) units by P2 be granted?


You must give a sequence.

d) If the system is in state S0, should a request of (2,0) units by P3 be granted?


You must give a sequence.

e) If the system is in state S0, should a request of (1,1) units by P2 be granted?


You must give a sequence.

Ans:) The above state is a safe state because:


Process Max Allocation Available Need
R1 R R1 R2 R1 R2 R1 R2
P0 4 2 2 2 3 6 2 0
P1 5 7 7 1 1 6
P2 4 6 6 1 1 5
P3 6 4 4 2 3 2

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:

1. If Request I ≤ Need i , go to step 2. Otherwise, raise an error condition, since the


process had exceeded its maximum claim.
2. If Request I ≤ Available, go to step 3, otherwise, P I must wait, since the resources are
not available.
3. Here the system pretend to have allocated the requested resources to process Pi by
modifying the state as follows:

Available : = Available – Request;


Allocation : = Allocation I + Request ;
Need I : Need I – Request i ;
If the resulting resource – allocation state is safe, the transaction is completed and process
P i is allocated its resources.

b) If the system is in state so, should a request of (0,2) units by p2 be granted? You must
give a sequence.

Step1: Request (P2) = (0,2)


Need(P2) = (1,5)
If Request (P2) ≤ Need(P2) than step2.
Step2: If Request (P2) (0,2) ≤ Available (3,6) than step3
Step 3: Available : = (3,6) + (0,2) = (3, 5)
Allocation(P2) = (3,1) – (0,2) = (1, 3)
Than possible sequence : <P2, P0P3P1>.

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.

Step1: Request(P2) ≤ Need (P3)


(2,0) ≤ (3,2) than step 2.
Step 2: If Request (P3) ≤ Available
(2,0) ≤ (3,6) than step 3.
Step 3: Available : (3,6) – (2,0) = (1,6)
Allocation (P3) = (3,2) + (2,0) = (5,2)
Need (P3) = (3,2) – (2,0) = (1,2)
Than possible sequence : <P3, P1,P2,P0>.

Q5)
a) List the security attacks that cannot be prevented by encryption.

Ans) Attacks against the encryption scheme ( cryptoanalysis attacks).

• 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.

b) Describe why authentication is important for file protection.

Ans) The process of identifying an individual, usually based on a username and


password. In security systems, authentication is distinct from authorization, which is the
process of giving individuals access to system objects based on their identity.
Authentication merely ensures that the individual is who he or she claims to be, but says
nothing about the access rights of the individuals.
Authentication is the process of determining whether someone is, in fact, who or
what it is declared to be. The process of identifying an individual, usually based on a
username and password. In security systems, authentication is distinct from authorization,
which is the process of giving individuals access to system objects based on their identity.
Authentication merely ensures that the individual is who he or she claims to be, but says
nothing about the access rights of the individual. It is also used for file protection for
unauthorised users.

Q6:)
Discuss in detail the Process management, Memory management, I/O and File
management and Security and Protection in LINUX Operating System.

Ans) Process Management:


The cpu executes a large number of programs while its main concern is the
excution of uer programs, the cpu is also needed for other system activities. These activities are
called processs. A process is a program in execution. Typically a batch job is a process. A time
shared user program is a process. A system task, such as spooling is also a process. For now, a
process may be considered as a job or time shared program, but the concept is actually more
general.
The Operating System is responsible for the following activities in connection with
process managemet.
• The creation and deletion of both user and system process.
• The suspension and resumption of process.
• The provision of mechanisms for process synchronization.
• The provision of mechanism for deadlock handling.

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.

I/O and File Management:


One of the purpose of an Operating System is to hide the peculiarities or specific
hardware devices from the user. For example in UNIX, the peculiarities of I/O devices are hidden
from the bulk of the Operating System itself by the I/O System. The Operating System is
responsible for the following activities in connection to I/O management.
• A buffer caching system.
• To activate a general device driver code.
• To run the driver software for specific hardware devices as and when
required.
File Management is one of the most visible services of an Operating System. Computers
can store information in several different physical forms: magnetic tapes, disk and drum
are the most common forms. Each of these devices has its own characteristics and
physical organisation.
The Operating System implements the abstract concept of the file by managing
mass storage device such as types and disks. Also files are normally organised into
directories to ease their use. Finally, when multiple users have access to files it may be
desirable to control by whom and in what ways files may be accessed.
The Operating System is responsible for the following activities in connection to
the file management.
• The creation and deletion of files.
• The creation and directory.
• The support of primitives for manipulating files and directories.
• The mapping of files on to disk storage.
• Backup of files on stable storage.
• Protection and security of the files.

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.

Вам также может понравиться