OS Practical Solutions of Record
OS Practical Solutions of Record
OSOperating Systems
For
B.Sc.(CS) Final Year — V SEMESTER
Prepared By:
OUTPUT:
Input:
Enter the number of processes: 3
Enter the Process Name, Arrival Time & Burst Time: 1 4 6
Enter the Process Name, Arrival Time & Burst Time: 2 5 15
Enter the Process Name, Arrival Time & Burst Time: 3 6 11
Output:
Pname arrivaltime executiontime waitingtime tatime
1 4 6 0 6
3 6 11 4 15
2 5 15 16 31
Average Waiting Time: 6.6667 Average Turn Around Time: 17.3333
OUTPUT:
Input:
Enter the number of processes: 3
Enter the Process Name, Arrival Time, execution time & priority: 1 2 3 1
Enter the Process Name, Arrival Time, execution time & priority: 2 4 5 2
Enter the Process Name, Arrival Time, execution time & priority: 3 5 6 3
Output:
PnamearrivaltimeexecutiontimePrioritywaitingtimetatime
1 2 3 1 0 3
2 4 5 2 1 6
3 5 6 3 5 11
Average Waiting Time: 2.0000 Average Turn Around Time: 6.6667
4. A program to simulate the Round Robin CPU scheduling
algorithm.
PROGRAM:
#include<stdio.h> #include<conio.h> void main()
{
int et[30],ts,n,i,x=0,tot=0; char pn[10][10];
clrscr();
printf("Enter the no of processes:"); scanf("%d",&n);
printf("Enter the time quantum:"); scanf("%d",&ts);
Prepared By: Waseem Raza MDMCA-TSSET 5
Downloaded from : www.sucomputersforum.com
for(i=0;i<n;i++)
{
printf("enter process name & estimated time:"); scanf("%s %d",pn[i],&et[i]);
}
printf("The processes are:"); for(i=0;i<n;i++)
printf("process %d:%s\n",i+1,pn[i]); for(i=0;i<n;i++)
tot=tot+et[i]; while(x!=tot)
{
for(i=0;i<n;i++)
{
if(et[i]>ts)
{
x=x+ts;
printf("\n %s -> %d",pn[i],ts); et[i]=et[i]-ts;
}
else if((et[i]<=ts)&&et[i]!=0)
{
x=x+et[i];
printf("\n %s -> %d",pn[i],et[i]); et[i]=0;}
}
}
printf("\n Total Estimated Time:%d",x); getch();
}
OUTPUT:
Input:
Enter the no of processes: 2
Enter the time quantum: 3
Enter the process name & estimated time: p1 12
Enter the process name & estimated time: p2 15
Output:
p1 ->3
p2 ->3
p1 ->3
p2 ->3
p1 ->3
p2 ->3
p1 ->3
p2 ->3
p2 ->3
Total Estimated Time: 27
OUTPUT:
Input:
Enter the memory capacity: 80
Enter no of processes: 2
Enter memory req for process1: 23
Output:
The memory allocated for process1 is: 23
Remaining memory is: 57
External fragmentation for this process is: 57
Enter memory req for process2: 52
The memory allocated for process2 is: 52
Remaining memoryis: 5
External fragmentation for this process is: 5
OUTPUT:
Input:
Enter the memory size: 80
Enter the no of partitions: 4
Each partition size: 20
Enter the number of processes: 2
Enter the memory req for process1: 18
Output:
Process1 is allocated in partn1
Internal fragmentation for process1 is: 2
Enter the memory req for process2: 22
Process is not allocated in partition 2
External fragmentation for process2 is: 18
Process memory allocated
1 20 18
2 20 22
The tot no of fragmentation is: 20
j=0;
for(i=1;i<=n;i++)
{
totalloc[k]=j+resalloc[i][k];
j=totalloc[k];
}
}
for(i=1;i<=n;i++)
{
if(block[i]==1||run[i]==1) active[i]=1;
Prepared By: Waseem Raza MDMCA-TSSET 9
Downloaded from : www.sucomputersforum.com
else active[i]=0;
}
for(k=1;k<=r;k++)
{
resalloc[p][k]+=newreq[k];
totalloc[k]+=newreq[k];
}
for(k=1;k<=r;k++)
{
if(totext[k]-totalloc[k]<0)
{
u=1;break;
}
}
if(u==0)
{
for(k=1;k<=r;k++)
simalloc[k]=totalloc[k];
for(s=1;s<=n;s++)
for(i=1;i<=n;i++)
{
if(active[i]==1)
{ j=0;
for(k=1;k<=r;k++)
{
if((totext[k]-simalloc[k])<(max[i][k]-resalloc[i][k]))
{
j=1;break;
}}}
if(j==0)
{
active[i]=0;
for(k=1;k<=r;k++)
simalloc[k]=resalloc[i][k];
}
}
m=0;
for(k=1;k<=r;k++)
resreq[p][k]=newreq[k];
printf("Deadlock willn't occur");
}
else
{
for(k=1;k<=r;k++)
{
resalloc[p][k]=newreq[k];
totalloc[k]=newreq[k];
}
printf("Deadlock will occur");
}
getch();
}
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int cl[10][10],al[10][10],av[10],i,j,k,m,n,ne[10][10],flag=0;
clrscr();
printf("\nEnter the matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the claim matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&cl[i][j]);
}}
printf("\nEnter allocated matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&al[i][j]);
}}
printf("\nThe need matrix:\n"); for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
ne[i][j]=cl[i][j]-al[i][j];
printf("\t%d",ne[i][j]);
}
printf("\n");
}
printf("\nEnter avaliable matrix");
for(i=0;i<n;i++)
scanf("%d",&av[i]);
Prepared By: Waseem Raza MDMCA-TSSET 11
Downloaded from : www.sucomputersforum.com
printf("Claim matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",cl[i][j]);
}
printf("\n");
}
printf("\n Allocated matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("\t%d",al[i][j]);
}
printf("\n");
}
printf("Available matrix:\n");
for(i=0;i<n;i++)
{
printf("%d\t",av[i]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(av[j]>=ne[i][j])
flag=1;
else
flag=0;
}}
if(flag==0)
printf("Unsafe State");
else
printf("Safe State");
getch();
}
OUTPUT:
Input:
Enter the claim matrix:3 2 2 6 1 3 3 1 4 4 2 2
Enter allocated matrix:1 0 0 5 1 1 2 1 1 0 0 2
The need matrix:
2 22
1 02
1 03
4 20
Enter available matrix1 1 2
Output:
Claim matrix: 3 2 2
6 13
3 14
4 22
Prepared By: Waseem Raza MDMCA-TSSET 12
Downloaded from : www.sucomputersforum.com
Allocated matrix: 1 0 0
5 11
2 11
0 02
Available matrix: 1 1 2 Safe State
OUTPUT:
Input:
Enter the Number of Pages: 12
Enter 12 Page Numbers:
232152453252
Prepared By: Waseem Raza MDMCA-TSSET 13
Downloaded from : www.sucomputersforum.com
Output:
2 2-> F
3 23-> F
2 23
1 231-> F
5 531-> F
2 521-> F
4 524-> F
5 524
3 324-> F
2 324
5 354-> F
2 352-> F
No of faults: 9