Oslab 34 45
Oslab 34 45
Date:
BANKERS ALGORITHM FOR DEADLOCK
AVOIDANCE.
AIM:
To write a C program to implement banker's algorithm for deadlock avoidance
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the memory for the process.
Step-3: Read the number of process, resources, allocation matrix and available matrix.
Step-4: Compare each and every process using the banker's algorithm.
Step-5: If the process is in safe state then it is a not a deadlock process otherwise it is a
deadlock process.
Step-6: produce the result of state of process.
Step-7: Stop the program.
PROGRAM:
#include <stdio.h>
#include <conio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n, r;
void input();
void show();
void cal();
int main() {
printf("********** Banker's Algorithm **********\n");
input();
show();
cal();
getch();
return 0;
}
void input() {
int i, j;
printf("Enter the number of Processes: ");
scanf("%d", &n);
printf("Enter the number of resource instances: ");
scanf("%d", &r);
RESULT:
Thus the C Program for implementation of banker's algorithm for deadlock avoidance
has been written and Executed Successfully.
Ex no: 8
Date:
ALGORITHMFORDEADLOCKDETECTION
AIM:
To write a C program to implement algorithm for deadlock detection
ALGORITHM:
Step-1: Start the program.
Step-2: Declare the memory for the process.
Step-3: Read the number of process, resources, allocation matrix and available matrix.
Step-4: Compare each and every process using the banker's algorithm.
Step-5: If the process is in safe state then it is a not a deadlock process otherwise it is a
deadlock process.
Step-6: produce the result of state of process.
Step-7: Stop the program.
PROGRAM:
#include <stdio.h>
#include <conio.h>
int max[100][100];
int alloc[100][100];
int need[100][100];
int avail[100];
int n, r;
void input();
void show();
void cal();
int main() {
printf("****** Deadlock Detection Algorithm ******\n");
input();
show();
cal();
getch();
return 0;
}
void input() {
int i, j;
printf("Enter the number of Processes: ");
scanf("%d", &n);
printf("Enter the number of resource instances: ");
scanf("%d", &r);
RESULT:
Thus the C Program for implementation of algorithm for deadlock detection has been
written and Executed Successfully.
Ex no: 9
THREADING&SYNCHONIZATIONAPPLICATIONS
Date:
AIM:
To write a c program to implement Threading and Synchronization Applications
ALGORITHM:
Step 1: Start the process.
Step 2: Declare process thread, thread-id.
Step 3: Read the process thread and thread state.
Step 4: Check the process thread equals to thread-id by using if condition.
Step 5: Check the error state of the thread.
Step 6: Display the completed thread process.
Step 7: Stop the program.
PROGRAM:
#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
pthread_ttid[2];
void* doSomeThing(void *arg)
{
unsigned long i = 0;
pthread_t id = pthread_self();
if(pthread_equal(id,tid[0]))
{
printf("\n First thread processing\n");
}
else
{
printf("\n Second thread processing\n");
}
for(i=0; i<(0xFFFFFFFF);i++);
return NULL;
}
int main(void)
{
int i = 0;
int err;
while(i< 2)
{
err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
else
printf("\n Thread created successfully\n");
i++;
}
sleep(5);
return 0;
}
RESULT: