### Safe state in OS

SAFE STATE IN OPERATING SYSTEM:

Let us consider a system with 12 magnetic tape drives and 3 processes. P1,P2 and P2. Process P1 requires 10 tape drives, process P2 requires 4 tape drives and process P3 may need up to 9 tape drives. Suppose, at time t0, process P1 is holding 5 tape drives, process P2 is holding 2 tape drives and process P3 is holding 2 tape drives.

 Processes Maximum needs Current needs P1 10 05 P2 04 02 P3 09 02

TOTAL NUMBER OF TAPE DRIVES = 12
NUMBER OF FREE TAPE DRIVES = 12-9=3

P2 allotted 2 tape drives, extra needs 2, so number of free tape drives = 1

Since P2 got its maximum need, it finishes its work and returns all the 4 tape drives.

Now number of free tape drives = 1+4 = 5

P1 allotted 5, extra needs 5,  so number of free tape drives = 0.
Since P1 got its maximum need, it finishes its work and returns all the 10 tape drives.

Now number of free tape drives = 10

P2 allotted 2, extra needs 7, so number of free tape drives = 3.
P2 also got its maximum need and it finishes its work and returns all the tape drives.

The system is in safe state if the sequence is .