You are on page 1of 8

1

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.

Process Arrival Time Burst Priority


A 0.000 4 3
B 1.0001 3 4
C 2.0001 3 6
D 3.0001 5 5

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

2. Shortest Job First

3. Round Robin (Quantum=2)

4. Round Robin (Quantum=1)

Process Arrival Time Processing Time

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

b):-Illustrate the concept of semaphores? How it will be implemented in critical section


problem.

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 .

It has two standard atomic operation :

WAIT: If wait operation is executing then the value of semaphore is decrease.

SIGNAL: If signal operation is executing then the value of semaphore is increase.

There are two types of semaphore.

1)- Binary Semaphore

A binary semaphore is a semaphore with an integer value that can range only between 0 & 1 .

2)- Counting Semaphore


5

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 .

Counting semaphore use for count resource available.

Implemention of Semaphore in critical section problem.

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

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

5):How Deadlock prevention is different from deadlock avoidance ?

ANS: Four necessary condition must hold for Dead lock.

1)Mutual Exclusion2)Hold and Wait3)No Preemption4)Circular Wait

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

2)Resource Allocation Graph Algorithm

3)Banker’s Algorithm
7

6. (a) How Process is different from Thread. Discuss structure used for thread

management in detail.

ANS:-Difference between threads and processes.

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.

3.)Threads can directly communicate with other threads of its process;


processes must use intercrosses communication to communicate with sibling
processes.

4.)Threads have almost no overhead; processes have considerable overhead.

5.)New threads are easily created; new processes require duplication of the
parent process.

6).Threads can exercise considerable control over threads of the same


process; processes can only exercise control over child processes.

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

affect child processes.

Thread management: Routines that work directly on threads - creating, detaching,


joining, etc. They also include functions to set/query thread attributes (joinable, scheduling etc.)

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.

• pthread_attr_init and pthread_attr_destroy are used to initialize/destroy the thread


attribute object.

• Other routines are then used to query/set specific attributes in the thread attribute object.

Terminating Threads:
8

1) There are several ways in which a Pthread may be terminated:

• The thread returns from its starting routine (the main routine for the initial thread).

• The thread makes a call to the pthread_exit subroutine (covered below).

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

There are three types multithreading models

1) Many-to-one model.

2) One-to-one model.

3) Many-to-many model.

There are two types of thread cancellation.

1) Asynchronous cancellation.

2) Deferred cancellation.

b) How Interprocess communication is managed in Windows?

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.

You might also like