Você está na página 1de 8

University of Trinidad & Tobago

OPSY2003
Assignment #2 – 5% Process Management
University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

1. Differentiate between a thread and a process [4]

A process is an active set of instructions(active program) loaded into memory, currently being executed by the
computer processor, when multiple processes are created they run in separate memory spaces, they contain a
stack, heap section, data and text section, they run independently of each other but a thread is a path of execution
within a process , they can be multiple threads within a process, the key difference between threads and processes
is that threads can share their data, code section memory space and O.S resources amongst other threads,
whereas processes don’t share anything they run independently of each other.

2. Compare and contrast deadlock prevention with deadlock avoidance. [4]

Deadlock Prevention is based on the fact that if any of the four necessary conditions: Mutual exclusion,
Hold and Wait, No preemption and Circular wait is prevented a deadlock will not occur, it does not need the
knowledge of future process resource requests and it avoids the cost of detecting and resolving deadlocks
because this method would make any of mentioned four conditions false and avoid deadlocks.

However Deadlock Avoidance checks the state of the system in advance and sees if the allocation of a
resource will lead to a deadlock condition, if so it should wait, unlike deadlock prevention deadlock
avoidance requires knowledge of all future process requests. It uses the Bankers Algorithm to check all the
requests made by processes for resources, to check for safe state, if after granting request the system
remains in the safe state it allows the request and if not in safe state it does not allow request made by
process.

3. Identify the three conditions which can be denied to prevent a deadlock. [6]
Condition 1 Mutual exclusion – resources involved must be unshareable.

Condition 2 Hold and Wait – The processes must hold the resources that were already allocated to them while
waiting for other requested resources. If the process had to release its resources when a new resource or resources
were requested, deadlock could not occur because the process would not prevent others from using resources that it
controlled.

Condition 3 no pre-emption
The processes must not have resources taken away while that resource is being used. Otherwise, deadlock could not
occur since the operating system could simply take enough resources from running processes to enable any process to
finish.
University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

4. Compare and contrast the three thread models that exist [9]

Many to One model – In this model, multiple user threads are mapped to one kernel thread, when a user
thread makes a blocking system call the entire process blocks, since we have one kernel thread only one
user thread can access kernel at a time, so multiple threads can’t access multiprocessor at the same time.

Many to Many model – In this model, multiple user threads are mapped to many kernel threads(same or
lesser number), the number of kernel level threads are specific to the operating system, if a user thread is
blocked we can schedule other user thread to other kernel thread.

One to One model – In this model every user thread is mapped to a kernel thread, creating a user thread
requires a corresponding kernel thread.

5. Describe how semaphores provide synchronisation [6]


University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

6. Consider the following table as to the processes that are in the Os waiting for the processor :

Process Arrival time CPU cycle


1 0 5 Time Quantum = 2
2 2 7
3 1 4
4 3 2

a) Draw the Round Robin Gantt Chart [2]


University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

b) Draw the FIFO Gantt Chart [2]

c) Draw the SJF Gantt Chart [2]


University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

d) Draw the SRT Gantt Chart [2]

e) Complete the table with the corresponding calculations and their answers.

Fifo Calculations

Wait Time = Service Time – Arrival Time

P1 = 0

P2 = 9

P2 = 5

P4 = 16

Average Wait Time = 0+9+5+16/4 = 7.5

SRT

P1 = 0 – 0 = 0
University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

P2 = 11 – 2 = 9

P3 = 7 – 1 = 6

P4 = 5 – 3 = 2

Average Wait Time = 0 + 2 + 6 + 9/ 4 = 4.25

SJF

P1 = 6

P2 = 11

P3 = 2

P4 = 0

Average Waiting Time = 6 + 11 + 2 + 0/4 = 4.75

Round Robin

[2 x 8]

Scheduling Average Turnaround Time Average Wait Time


Method
Round
Robin
FIFO 7.5

SJF 4.75

SRT 4.25

7. Prove if the following state is a safe or unsafe state. [11]


University of Trinidad & Tobago
OPSY2003
Assignment #2 – 5% Process Management

Process Need
P0 210
P1 233
P2 020
P3 542
P4 900

Start with P0 gets max 222 new available = 332 – 210 = 122
Finishes releases max amount, new available = 122 + 222 = 344

P1 gets max 433, new available = 344 – 233 = 111


Finishes releases max amount, new available = 111 + 433 = 544

P2 gets max 322, new available = 544 – 020 = 524


Finishes releases max amount, new available = 524 + 322 = 846

P3 gets max 753, new available = 846 – 542 = 302


Finishes releases max amount, new available = 302 + 753 = 1057

P4 gets max 902, new available = 1057 – 900 = 157


Finishes releases max amount, new available = 157 + 902 = 10 5 9

P0, P1, P2, P3, P4 safe state

Você também pode gostar