Professional Documents
Culture Documents
ASSIGMENT NO -2
CSE-316
OPERATING SYSTEM
Submitted to: -
Submitted by:-
Kavita choudhary Yogesh
Gandhi
C2801B48
Reg. No-10808452
2
Part A
a) For the processes liked in table, draw a chart illustrating their execution
using Priority Scheduling. A larger priority number has higher priority.
a) Preemptive
b) Non preemptive
B):For a processes listed in Table, draw a chart illustrating their execution using:
3
1. First-Come-First-Served
A 0.000 3
B 1.001 6
C 4.001 4
D 6.001 2
ANS:-
1)
2)
4
3)
1 4 2 2
A B A B C D B C
0 2 4 5 7 9 11 13 15
4):-
2 1 5 4 3 3 2 1 2 1 1
A A B A B C B C D B C D B C B
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
15
ANS:- Sometimes a process may need to wait for some other process to finish before it can
continue. In this instance, the two processes need to be synchronized together,a common method
in operating systems is to use a variable called a semaphore.A semaphore is an integer variable
&this is use for multiple processing .
A binary semaphore is a semaphore with an integer value that can range only between 0 & 1 .
It must gurantee that no two process can execute wait and signal simultaneously. This
implemention becomes critical section problems where Wait() and signal() code are
placed in critical section .
Wait(S):
S.value := S.value - 1;
if S.value < < 0/tt>
then begin
add this process to S.L;
suspend this process; this code is executed atomically
end;
actual waiting is done by the suspended process signal(S):
S.value := S.value + 1;
if S.value 0
then begin
remove a process P from S.L;
wakeup(P);
end
Part B
b) a) Round robin can be termed as preemptive FCFS? Justify your answer with
an example.
ANS:- “YES” Round Robin can be termed as preemptive FCFS.In Round Robin a small unit of
time is defined ,called a Quantum Time.
If the Time Quantum is too large then Round Robin act as FCFS.
Example:-
Quantum Time =6
P1 5
P2 3
P3 4
b)In what kind of an environment can round robin be implemented over FCFS?
ANS:-In Real Time Scheduling environment Round Robin implemented over FCFS.In round
robin Time quantum is given , called time slice. A time quantum is generally from 10 to 100
milliseconds. Round robin similar to FCFS but only difference in between is when the no. of
process is less and process divide into time slice then RR implemented over FCFS. A rule of
thumb is that 80 percent of the CPU bursts should be shorter than the time quantum.
Dead lock Prevention:-At least one of these condition cannot hold, we prevent the occurrence of
a deadlock.
Deadlock avoidance:-The system dynamically considers every request and decides whether it is
safe to grant is at this point. The system requires additional option information regarding the
overall potential use of each resources for each process and Allow more accuracy.
1)Safe State
3)Banker’s Algorithm
7
6. (a) How Process is different from Thread. Discuss structure used for thread
management in detail.
1.)Threads share the address space of the process that created it; processes
have their own address.
2.)Threads have direct access to the data segment of its process; processes
have their own copy of the data segment of the parent process.
5.)New threads are easily created; new processes require duplication of the
parent process.
7.)Changes to the main thread (cancellation, priority change, etc.) may affect
the behavior of the other threads of the process; changes to the parent
process does not
Thread Attributes:
• By default, a thread is created with certain attributes. Some of these attributes can be
changed by the programmer via the thread attribute object.
• Other routines are then used to query/set specific attributes in the thread attribute object.
Terminating Threads:
8
• The thread returns from its starting routine (the main routine for the initial thread).
• The thread is canceled by another thread via the pthread_cancel routine (not covered
here).
• The entire process is terminated due to a call to either the exec or exit subroutines.
Thread management:- Thread contain the user threads and kernels threads, which has many
example such as POSIX Pthreads, MASH C-threads and Soleries 2UI-threads. Windows NT,
Windows 2000etc.
1) Many-to-one model.
2) One-to-one model.
3) Many-to-many model.
1) Asynchronous cancellation.
2) Deferred cancellation.
ANS:- When processes communicate with each other it is called "Inter-process communication"
(IPC). Processes frequently need to communicate, for instance in a shell pipeline, the output of
the first process need to pass to the second one, and so on to the other process. It is preferred in a
well-structured way not using interrupts.
It is even possible for the two processes to be running on different machines. The operating
system (OS) may differ from one process to the other, therefore some mediator(s)
(called protocols) are needed.