Safe State in operating systems

What is the state?

The state of the system informs that if resources are allocated to different processes then the system undergoes deadlock or not.

What is a safe state? Describe how a safe state helps to avoid deadlock

If the system can allocate resources to the process in such a way that it can avoid deadlock. Then the system is in a safe state.

What is an unsafe state?

If the system can’t allocate resources to the process safely, then the system is in an unsafe state.

Note: Unsafe state not always cause deadlock.

If a system is in a safe state, are we guaranteed it will never deadlock?

It’s true that “All safe states are deadlock free”, but don’t forgot that “all unsafe states not always lead to deadlocks”.

are safe state always absolutely deadlock free?

Yes, safe state are absolutely deadlock free.

Difference between safe and unsafe state in OS

Some common difference between  safe and unsafe state are mentioned below;

safe stateunsafe state
system safely allocate all resourcessystem is unable to safely allocate all resources
There is no deadlock

Safe state system will never deadlock.

unsafe state may lead to deadlock but not always.

Unsafe state system may lead to deadlock but not always.

 

Example of safe and unsafe state

Let’s see Deadlock avoidance safe and unsafe state example.

Consider the following set of processes to answer deadlock question. Is the system in a safe state

Free resources : 3

PROCESSAllocated RNeeded resources
P1410
P224
P327

Process P1 have 4 resources and 10 resources required for completion.

Process P2 have 2 resources and 4 resources required for completion.

Process P3 have 2 resources and 7 resources required for completion.

Total free resources for P1, P2 and P3 are 3.

Now, let’s move to other calculations.

Free resources: 1

PROCESSAllocated RNeeded resources
P1410
P244
P327

Free resources: 5

PROCESSAllocated RNeeded resources
P1410
P200
P327

Free resources : 0

PROCESSAllocated RNeeded resources
P1410
P200
P377

Free resources: 7

PROCESSAllocated RNeeded resources
P1410
P200
P300

Free resources: 1

PROCESSAllocated RNeeded resources
P11010
P200
P300

Free resources: 11

PROCESSAllocated RNeeded resources
P100
P200
P300

Now, after the termination of processes, we can see following results;

  • P1 have 0 resources and 0 resources required because P1 is no more in system.
  • P2 have 0 resources and 0 resources required because P2 is no more in system.
  • P3 have 0 resources and 0 resources required because P3 is no more in system.

Result: All processes execute successfully, so there is no deadlock and the system is in a safe state.

How is a safe state in OS achieved?

Safe state in Operating system can be achieved if the system can safely allocate all resources requested by all the processes in the system without entering a deadlock state.

Download Slides Presentations and PDF file of this tutorial

  1. Download safe state and unsafe state in OS deadlocks Slides Presentation
  2. Download safe state and unsafe state in OS deadlocks PDF File

Video Lecture

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]