OS Lab Manual
OS Lab Manual
Module - 1
Week Name of the Experiments CLA Assessments & marks distribution CLA marks
Module - 2
1 Applying various Deadlock Prevention & Avoidance 1 Objective & Procedure write up
Algorithms including outcomes - 4 Marks
2 Implementation of Page Replacement Algorithm using FIFO, 2 Experimentation and data collection -
LRU 4 Marks 20 Marks for
Computation of results - 4 Marks each CLA
3 Analyzing of various Memory management Techniques 3
Analysis of results and interpretation -
4 Implementation of Page Replacement Algorithm using 4 4 Marks
OPTIMAL
5 Implementation of Disk scheduling algorithm Viva voce - 4 Marks
6 Revision 5
fact=1
while [ $num -gt 1 ]
do
fact=$((fact * num)) #fact = fact * num
num=$((num - 1)) #num = num - 1
done
echo “The Factorail of a number is : $fact”
Output: Enter a number : 4
The Factorial of a numbe is: 24
7. Palindrome Program using Shell Script?
Ans:
echo “Enter a Number: "
read n
num=0
on=$n
while [ $n -gt 0 ]
do
num=$(expr $num \* 10)
k=$(expr $n % 10)
num=$(expr $num + $k)
n=$(expr $n / 10)
done
if [ $num -eq $on ]
then
echo palindrome
else
echo not palindrome
fi
Output: Enter a Number: 121
Palindrome
Enter a Number: 234
Not palindrome
MODULE-2
for(j=1;j<= rno;j++)
{
if(work[j]< need[i][j])
{
prc=0;
break;
}
}
}
if(prc!=0)
break;
}
if(prc!=0)
{
printf("\n Process %d completed",i);
count++;
printf("\n Available matrix:");
for(j=1;j<= rno;j++)
{
work[j]+=allocated[prc][j];
allocated[prc][j]=0;
max[prc][j]=0;
flag[prc]=1;
printf(" %d",work[j]);
}
}
}while(count!=pno&&prc!=0);
if(count==pno)
printf("\nThe system is in a safe state!!");
else
printf("\nThe system is in an unsafe state!!");
}
Output:
vignan@vignan:~/os$ ./a.out
2.Dining Philosophers(Avoidence):
#include<stdio.h>
#define n 4
int compltedPhilo = 0,i;
struct fork{
int taken;
}ForkAvil[n];
struct philosp{
int left;
int right;
}Philostatus[n];
void goForDinner(int philID){
if(Philostatus[philID].left==10 && Philostatus[philID].right==10)
printf("Philosopher %d completed his dinner\n",philID+1);
else if(Philostatus[philID].left==1 && Philostatus[philID].right==1){
printf("Philosopher %d completed his dinner\n",philID+1);
Philostatus[philID].left = Philostatus[philID].right = 10;
int otherFork = philID-1;
if(otherFork== -1)
otherFork=(n-1);
ForkAvil[philID].taken = ForkAvil[otherFork].taken = 0;
printf("Philosopher %d released fork %d and fork %d\n",philID+1,philID+1,otherFork+1);
compltedPhilo++;
}
else if(Philostatus[philID].left==1 && Philostatus[philID].right==0){
if(philID==(n-1)){
if(ForkAvil[philID].taken==0){
ForkAvil[philID].taken = Philostatus[philID].right = 1;
printf("Fork %d taken by philosopher %d\n",philID+1,philID+1);
}else{
printf("Philosopher %d is waiting for fork %d\n",philID+1,philID+1);
}
}else{
int dupphilID = philID;
philID-=1;
if(philID== -1)
philID=(n-1);
if(ForkAvil[philID].taken == 0){
ForkAvil[philID].taken = Philostatus[dupphilID].right = 1;
printf("Fork %d taken by Philosopher %d\n",philID+1,dupphilID+1);
}else{
printf("Philosopher %d is waiting for Fork %d\n",dupphilID+1,philID+1);
}
}
}
else if(Philostatus[philID].left==0){
if(philID==(n-1)){
if(ForkAvil[philID-1].taken==0){
ForkAvil[philID-1].taken = Philostatus[philID].left = 1;
printf("Fork %d taken by philosopher %d\n",philID,philID+1);
}else{
printf("Philosopher %d is waiting for fork %d\n",philID+1,philID);
}
}else{
if(ForkAvil[philID].taken == 0){
ForkAvil[philID].taken = Philostatus[philID].left = 1;
printf("Fork %d taken by Philosopher %d\n",philID+1,philID+1);
}else{
printf("Philosopher %d is waiting for Fork %d\n",philID+1,philID+1);
}
}
}else{}
}
int main(){
for(i=0;i<n;i++)
ForkAvil[i].taken=Philostatus[i].left=Philostatus[i].right=0;
while(compltedPhilo<n){
for(i=0;i<n;i++)
goForDinner(i);
printf("\nTill now num of philosophers completed dinner are %d\n\n",compltedPhilo);
}
return 0;
}
Output:
vignan@vignan:~$ ./a.out
Fork 1 taken by Philosopher 1
Fork 2 taken by Philosopher 2
Fork 3 taken by Philosopher 3
Philosopher 4 is waiting for fork 3
#include<stdio.h>
int main()
{
int i,j,n,a[50],frame[10],no,k,avail,count=0;
printf("\n ENTER THE NUMBER OF PAGES:\n");
scanf("%d",&n);
printf("\n ENTER THE PAGE NUMBER :\n");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf("\n ENTER THE NUMBER OF FRAMES :");
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
printf("\tref string\t page frames\n");
for(i=1;i<=n;i++)
{
printf("%d\t\t",a[i]);
avail=0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
avail=1;
if (avail==0)
{
frame[j]=a[i];
j=(j+1)%no;
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
}
printf("\n");
}
printf("Page Fault Is %d",count);
return 0;
}
Output:
vignan@vignan:~$ ./a.out
7 -1 -1
7 5 -1
7 5 9
4 5 9
4 3 9
4 3 7
9 3 7
9 6 7
9 6 2
1 6 2
Total Page Faults = 10
#include<stdio.h>
main()
{
int np,ps,i;
int *sa;
printf("enter how many pages\n");
scanf("%d",&np);
printf("enter the page size \n");
scanf("%d",&ps);
sa=(int*)malloc(2*np);
for(i=0;i<np;i++)
{
sa[i]=(int)malloc(ps);
printf("page%d\t address %u\n",i+1,sa[i]);
}
}
Output:
vignan@vignan:~$ ./a.out
enter how many pages
3
enter the page size
4
page1 address 151244824
page2 address 151244840
page3 address 151244856
Output:
FCFS Disk Scheduling Algorithm:
vignan@vignan:~$ ./a.out
Enter the number of Requests
8
Enter the Requests sequence
95 180 34 119 11 123 62 64
Enter initial head position
50
Total head moment is 644
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
RQ[index]=1000;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}
Output:
vignan@vignan:~$ ./a.out
Enter the number of Requests
8
Enter the Requests sequence
95
180
34
119
11
123
62
64
Enter initial head position
50
Total head movement is 236