SAFETY ALGORITHM
#1

Presented by:
Shabaaz N Syed
Vedprakash Anad

[attachment=12492]
SAFETY ALGORITHM
Theory:

The safety algorithm is run by the operating system whenever a process requests resources. The algorithm avoids deadlock by denying or postponing the request if it determines that accepting the request could put the system in an unsafe state (one where deadlock could occur). When a new process enters a system, it must declare the maximum number of instances of each resource type that may not exceed the total number of resources in the system. Also, when a process gets all its requested resources it must return them in a finite amount of time.
Resources
For the safety algorithm to work, it needs to know three things:
• How much of each resource each process could possibly request.
• How much of each resource each process is currently holding.
Resources may be allocated to a process only if it satisfies the following conditions:
1. request ≤ max, else set error condition as process has crossed maximum claim made by it.
2. request ≤ available, else process waits until resources are available.
Some of the resources that are tracked in real systems are memory, semaphores and interface access
PROGRAM
#include<stdio.h>
#include<conio.h>
int i,j,reso,proc,resoinst[20],alloc[20][20],max[20][20],avail[20],need[20][20];
int safeflg=0,safeseq[20]; //GLOBAL VARIABLES
void printreso(int proc) // FUNCTION USED TO PRINT FORMAT TABLE
{
for(i=1;i<=proc;i++)
{
for(j=65;j<=64+reso;j++)
printf("%c ",j);
for(j=1;j<=reso*proc/2;j++)
printf(" ");
}
}
void availability(void) //FUNCTION USED TO CHECK AVAILABILTY OF RESOURCES
{ //FUNCTION CAN BE FURTHUR USED TO FIND SAFE SEQUENCE
int temp=0;
for(i=1;i<=reso;i++)
{
for(j=1;j<=proc;j++)
temp=temp+alloc[j][i];
avail[i]=resoinst[i]-temp;
temp=0;
}
}
void main(void) //START OF MAIN PROGRAM
{
clrscr();
printf("ENTER TOTAL NOS OF PROCESSES & RESOURES: ");
scanf("%d %d",&proc,&reso); //READING PROCESSES & RESOURCES
printf("\nENTER RESOURCE INSTANCES\n");
for(i=65;i<65+reso;i++)
{
printf("RESOURCE %c",i);
scanf("%d",&resoinst[i-64]);
}
clrscr();
printf("PROCESS");
for(i=1;i<=reso;i++)
printf(" ");
printf("ALLOCTION");
for(i=1;i<=reso;i++)
printf(" "); // PRINTING TABLE IN FORMAT
printf("MAX");
for(i=1;i<=reso;i++)
printf(" ");
printf("\n ");
printreso(2);
for(i=1;i<=proc;i++)
{
printf("\nP%d ",i-1);
for(j=1;j<=reso;j++)
scanf("%d",&alloc[i][j]); // READING RESOURCE DATA
for(j=1;j<=reso;j++)
scanf("%d",&max[i][j]);
}
printf("\nAVAILABLE\n");
printreso(1); printf("\n");
availability();
for(i=1;i<=reso;i++)
printf("%d ",avail[i]);
printf("\n\nNEED\n ");
printreso(1);
for(i=1;i<=proc;i++)
for(j=1;j<=reso;j++)
need[i][j]=max[i][j]-alloc[i][j]; // CALCULATING THE NEED
for(i=1;i<=proc;i++)
{
printf("\nP%d ",i);
for(j=1;j<=reso;j++)
printf("%d ",need[i][j]);
}
for(i=1;i<=proc;i++)
{
for(j=1;j<=reso;j++)
{
if(need[i][j]<=avail[j]);
else
safeflg=1; // SAFE FLAG SETS IF SYSTEM IS UNSAFE
}
}
getch();
clrscr();
if(safeflg==1)
printf("\n\nSYSTEM NOT IN SAFE STATE");
else
printf("\n\nSYSTEM IN SAFE STATE");
getch();
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: safety algorithm c code of operating system, program for safety algorithm, safety algorithm in c, safety algorithm, conio h, safety algorithm code,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  PIR BASED AUTO DIALER SECURITY and SAFETY ALARM seminar presentation 3 4,642 21-11-2012, 11:41 AM
Last Post: seminar details
  ODAM: An Optimized Distributed Association Rule Mining Algorithm computer science crazy 5 3,358 23-01-2012, 11:56 AM
Last Post: seminar addict
  quantum cost optimization algorithm full report computer science crazy 0 890 16-01-2012, 06:02 PM
Last Post: computer science crazy
  Simulation of Dijkstra Routing Algorithm full report project topics 2 3,817 30-11-2011, 10:22 PM
Last Post: VickyBujju
  Residential Safety System with Gas and Fire Detection and Auto Intimation to User Mob science projects buddy 6 2,948 05-10-2011, 01:49 PM
Last Post: devilzxtreme
  An Adaptive Algorithm for Incremental Mining of Association Rules smart paper boy 0 1,027 30-08-2011, 09:38 AM
Last Post: smart paper boy
  A Time-Varying Convergence Parameter for the LMS Algorithm in the Presence of White smart paper boy 0 930 19-08-2011, 10:37 AM
Last Post: smart paper boy
  An Adaptive K-means Clustering Algorithm for Breast Image Segmentation smart paper boy 0 1,143 29-07-2011, 02:19 PM
Last Post: smart paper boy
  A MPPT ALGORITHM FOR SINGLE-PHASE SINGLE-STAGE PHOTOVOLTAIC CONVERTERS smart paper boy 0 1,548 28-07-2011, 03:45 PM
Last Post: smart paper boy
  A New Fast Acquisition Algorithm for GPS Receivers smart paper boy 0 750 28-07-2011, 03:42 PM
Last Post: smart paper boy

Forum Jump: