OS Lab Manual (02.07.24)
OS Lab Manual (02.07.24)
LAB MANUAL
Prepared by Approved by
Mr. Ashish Kumar Srivastava Prof. (Dr.) Mahendra Sharma
Index
Vision:
Mission:
Vision:
To produce competent IT Professionals empowered with Research Aptitude and high ethical
values and cater the need of Industry and society.
Mission:
TTo attain academic and professional excellence with collective efforts of all stakeholders through:
1. Research – To impart quality education with innovative teaching learning processes to develop a culture
of research and innovation.
2. Industry – Interact with industry academia for better employability of students.
3. Ethical Values/ Society – To inculcate ethical values and social responsibility in students &
professional excellence with collective efforts of all stakeholders through:
1. Research – To impart quality education with innovative teaching learning processes to
develop a culture of research and innovation.
2. Industry – Interact with industry academia for better employability of students.
3. Ethical Values/ Society – To inculcate ethical values and social responsibility in students.
DEPARTMENT OF INFORMATION TECHNOLOGY
CO 3: Apply various deadlock policies & memory management concepts and verify the performance.
CO 4: Implement various page replacement algorithms and verify the associated performance.
PO1 - Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the Solution of complex engineering problems.
PO2 - Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
PO3 - Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
PO4 - Conduct Investigations of Complex Problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
PO5 - Modern Tool Usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6 - The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO7 - Environment and Sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8 - Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
PO9 - Individual and Team Work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO10 - Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
PO11 - Project Management and Finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader.
PO12 - Life-long Learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PROGRAM SPECIFIC OUTCOMES:
PSO1: Apply and acquire knowledge of computer networks in implementation of communication and
reliable network systems.
PSO2: Design and implement knowledge based discovery by using the concept of DBMS
CO-PO Mapping:
Course
P PO PO PO PO PO PO PO PO PO PO PSO PSO
Outcome PO1
O2 3 4 5 6 7 8 9 10 11 12 1 2
s
CO PO1 P PO PO PO5 PO6 PO7 PO PO PO PO PO PSO PSO
O2 3 4 8 9 10 11 12 1 2
CO1 2 3 1 1 2 2 2 1
CO2 3 2 2 3 2 2 2 2
CO3 3 2 2 3 2 2 2 2
CO4 3 2 2 3 2 2 2 2
CO5 3 2 2 3 2 2 2 2
2.2 1.8 2.6 2.0 1
Average 2.80 2.00 2.00 1.80
0 0 0 0
1. Study of hardware and software requirements of different operating systems (UNIX, LINUX,
WINDOWS XP, WINDOWS7/8 )
2. Execute various UNIX system calls for i. Process management ii. File management iii.
Input/output Systems calls
3. Implement CPU Scheduling Policies: i. SJF ii. Priority iii. FCFS iv. Multi-level Queue
4. Implement file storage allocation technique: i. Contiguous (using array) ii. Linked –list(using
linked-list) iii. Indirect allocation (indexing)
5. Implementation of contiguous allocation techniques: i. Worst-Fit ii. Best- Fit iii. First- Fit
6. Calculation of external and internal fragmentation i. Free space list of blocks from system ii.
List process file from the system
7. Implementation of compaction for the continually changing memory layout and calculate total
movement of data
8. Implementation of resource allocation graph RAG)
9. Implementation of Banker‟s algorithm
10. Conversion of resource allocation graph (RAG) to wait for graph (WFG) for each type of
method used for storing graph.
11. Implement the solution for Bounded Buffer (producer-consumer)problem using inter process
communication techniques-Semaphores
12. Implement the solutions for Readers-Writers problem using inter process communication
technique –Semaphore
DEPARTMENT OF INFORMATION TECHNOLOGY
LIST OF EXPERIMENTS:
Lab Instructions
Objective: to make familiar with hardware and software requirements for the different
types of operating systems.
Steps to be followed
UNIX:
Hardware Requirements:
UNIX kernel
Command line interface
LINUX:
Hardware Requirements:
Linux kernel
Graphical User Interface (GUI)
Command line interface
WINDOWS XP:
Hardware Requirements:
Hardware Requirements:
500MB of free hard disk space is the minimum requirement, but again, more is
recommended depending on the intended use case.
Software Requirements:
The UNIX kernel is the core of the operating system and provides the basic functionality
for all other software to run on top of.
The command line interface (CLI) is the primary way to interact with the system, using
text-based commands to perform tasks like navigating the file system, launching
applications, and managing users and permissions.
LINUX:
Hardware Requirements:
Most modern Linux distributions recommend at least 512MB of RAM, but some
distributions may require more depending on the intended use case.
20GB of free hard disk space is recommended, but again, this can vary depending on the
intended use case.
Software Requirements:
The Linux kernel is the core of the operating system and provides the basic functionality
for all other software to run on top of.
Most Linux distributions include a graphical user interface (GUI) that provides a visual
way to interact with the system. Some distributions may also offer alternative interfaces,
like a command line interface (CLI) or a text-based interface.
The CLI is the traditional way to interact with Linux, using text-based commands to
perform tasks like navigating the file system, launching applications, and managing users
and permissions.
WINDOWS XP:
Hardware Requirements:
64MB of RAM is the minimum requirement for Windows XP to run, but 128MB or more
is recommended for better performance.
1.5GB of free hard disk space is the minimum requirement, but more is recommended
depending on the intended use case.
Software Requirements:
Windows XP is a complete operating system that includes a graphical user interface and
support for a wide range of hardware and software applications.
DirectX 9.0c or higher is required to run some advanced graphics applications and games.
WINDOWS 7/8:
Hardware Requirements:
Windows 7/8 require at least 1GB of RAM to run, but 2GB or more is recommended for
better performance.
At least 16GB of free hard disk space is required for a 32-bit installation of Windows 7/8,
or 20GB for a 64-bit installation.
A 1 GHz or faster processor is required for both 32-bit and 64-bit versions.
Software Requirements:
Windows 7/8 include a graphical user interface and support for a wide range of hardware
and software applications.
DirectX 9 graphics device with WDDM 1.0 or higher driver is required to run some
advanced graphics applications and games.
Windows 10/11
Hardware Requirements:
Experiment No. 2
Experiment 2. Execute various UNIX system calls for i. Process management ii. File
management iii. Input/output Systems calls
Objective : To make familiar with unix system calls for the process, file and input output
management.
Steps to be followed:
We will use online linuxcompiler : onecompiler.com
Program: Use of fork system call
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
intmain()
{
fork();
printf("Using fork() system call\n");
return 0;
}
Output:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
intmain()
int p=getpid();
fork();
return 0;
}
Output:
Using fork() system call
the process id is : 7943Using fork() system call
the process id is : 7943
Experiment No. 3
Experiment -3
Experiment Objective-: C Program for FCFS CPU scheduling algorithm
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating
system algorithm
Program Code:-
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5];
int tot=0,wt[10],i,n;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\tP_time\tw_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\navg waiting time=%f",tot,avg);
getch();
}
ProgramOutput:
enter no of processes: 5
Enterprocess1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
Experiment-4
Experiment Objective: C program for SJF CPU Scheduling Algorithm
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating
system algorithm
Program Code:-
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pt[i]>pt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
Program Output:
enter no of processes: 5
enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1
p_nameP_time w_time
eee 1 0
ccc 2 1
bbb 3 3
aaa 4 6
ddd 5 10
total waiting time=20
avg waiting time=4.00
Experiment No. 5
Experiment-5
Experiment Objective: Shortest Remaining Time First ( SRTF) CPU scheduling in c
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating
system algorithm
Program Code:-
#include <stdio.h>
intmain()
{
int a[10],b[10],x[10],i,j,smallest,count=0,time,n;
double avg=0,tt=0,end;
printf("enter the number of Processes:\n");
scanf("%d",&n);
printf("enter arrival time\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter burst time\n");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
x[i]=b[i];
b[9]=9999;
for(time=0;count!=n;time++)
{
smallest=9;
for(i=0;i<n;i++)
{
if(a[i]<=time && b[i]<b[smallest] && b[i]>0 )
smallest=i;
}
b[smallest]--;
if(b[smallest]==0)
{
count++;
end=time+1;
avg=avg+end-a[smallest]-x[smallest];
tt= tt+end-a[smallest];
}
}
printf("\n\nAverage waiting time = %lf\n",avg/n);
printf("Average Turnaround time = %lf",tt/n);
return 0;
}
Program Output:-
Enter the number of Processes:
4
enter arrival time
0
1
2
3
enter burst time
8
4
9
5
Average waiting time = 6.500000
Average Turnaround time = 13.000000
Experiment No. 6
Experiment-6
ExperimentObjective:-C Program for Priority CPU Scheduling Algorithm
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating system
algorithm
Program Code:-
#include<stdio.h>
#include<conio.h>
void main()
{
char p[10][5],temp[5];
inti,j,pt[10],wt[10],totwt=0,pr[10],temp1,n;
float avgwt;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:",i+1);
scanf("%s",&p[i]);
printf("enter process time:");
scanf("%d",&pt[i]);
printf("enter priority:");
scanf("%d",&pr[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(pr[i]>pr[j])
{
temp1=pr[i];
pr[i]=pr[j];
pr[j]=temp1;
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
totwt=totwt+wt[i];
}
avgwt=(float)totwt/n;
printf("p_name\tp_time\t priority\tw_time\n");
for(i=0;i<n;i++)
{
printf(" %s\t %d\t %d\t %d\n" ,p[i],pt[i],pr[i],wt[i]);
}
printf("total waiting time=%d\navg waiting time=%f",tot,avg);
getch();
}
Program Output:
enter no of processes: 5
enter process1 name: aaa
enter process time: 4
enter priority:5
enter process2 name: bbb
enter process time: 3
enter priority:4
enter process3 name: ccc
enter process time: 2
enter priority:3
enter process4 name: ddd
enter process time: 5
enter priority:2
enter process5 name: eee
enter process time: 1
enter priority:1
count=0;
for(i=0;i<m;i++)
{
for(j=i+1;j<=n;j++)
{
if(strcmp(p[i],p[j])==0)
{
count++;
found=j;
}
}
if(found!=0)
{
wt[i]=wt[found]-(count*timer);
count=0;
found=0;
}
}
for(i=0;i<m;i++)
{
totwt+=wt[i];
}
avgwt=(float)totwt/m;
for(i=0;i<m;i++)
{
printf("\n%s\t%d\t%d",p[i],pt[i],wt[i]);
}
printf("\ntotal waiting time %d\n",totwt);
printf("total avgtime %f",avgwt);
}
Program Output :
enter the process name : aaa
enter the processing time : 4
enter the process name : bbb
enter the processing time : 3
enter the process name : ccc
enter the processing time : 2
enter the process name : ddd
enter the processing time : 5
enter the process name : eee
enter the processing time : 1
Experiment-8
Experiment Objective:-Multi Level Queue Scheduling
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating
system algorithm
Program Code:
/*Write a C program to simulate multi-level queue scheduling algorithm considering the
following scenario. All the processes in the system are divided into two categories -
system processes and user processes. System processes are to be given higher priority
than user processes. The priority of each process ranges from 1 to 3.
Use fixed priority scheduling for all the processes.*/
#include<stdio.h>
#include<stdlib.h>
main()
{
int p[30],bt[30], su[30], wt[30],tat[30],i, k, n, temp;
float waiting_avg, turnaround_avg;
inttr;
intcsource=0;
intcuser=0;
intbtsource[30],btuser[30],puser[30],psource[30];
printf("Enter the number of processes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("System process/User Process (0/1) : ");
scanf("%d", &tr);
printf("Enter the Burst Time of Process %d : ", i);
if(tr==1){
scanf("%d",&btuser[cuser]);
puser[cuser]=i;
cuser++;
}
else if(tr==0){
scanf("%d",&btsource[csource]);
psource[csource]=i;
csource++;
}
}
for(i=0;i<csource;i++){
p[i]=psource[i];
bt[i]=btsource[i];
su[i]=0;
}
for(i=0;i<cuser;i++){
p[i+csource]=puser[i];
bt[i+csource]=btuser[i];
su[i+csource]=1;
}
for(i=0;i<n;i++){
printf("%d %d",p[i],bt[i]);
}
waiting_avg = wt[0] = 0;
turnaround_avg = tat[0] = bt[0];
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
tat[i] = tat[i-1] + bt[i];
waiting_avg = waiting_avg + wt[i];
turnaround_avg = turnaround_avg + tat[i];
}
printf("\nPROCESS\t SYSTEM/USER PROCESS \tBURST TIME\tWAITING TIME\tTURNAROUND TIME");
for(i=0;i<n;i++)
printf("\n%d \t\t %d \t\t %d \t\t %d \t\t %d ",p[i],su[i],bt[i],wt[i],tat[i]);
printf("\nAverage Waiting Time is : %f",waiting_avg/n);
printf("\nAverage Turnaround Time is :%f\n",turnaround_avg/n);
}
Output
/tmp/V1OrAZNYcG.o
0 51 32 83 44 5
PROCESS SYSTEM/USER PROCESS BURST TIME WAITING TIME TURNAROUND TIME
0 0 5 0 5
1 0 3 5 8
2 1 8 8 16
3 1 4 16 20
4 1 5 20 25
Experiment-9
ExperimentObjective:-Program for FIFO page replacement algorithm
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating
system algorithm
Program Code:-
#include<stdio.h>
#include<conio.h>
intfr[3];
void main()
{
void display();
inti,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2};
int flag1=0,flag2=0,pf=0,frsize=3,top=0;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0;
flag2=0;
for(i=0;i<12;i++)
{
if(fr[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<frsize;i++)
{
if(fr[i]==-1)
{
fr[i]=page[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
fr[top]=page[j];
top++;
pf++;
if(top>=frsize)
top=0;
}
display();
}
printf("Number of page faults : %d ",pf);
getch();
}
void display()
{
inti;
printf("\n");
for(i=0;i<3;i++)
printf("%d\t",fr[i]);
}
Program Output :
2 -1 -1
2 3 -1
2 3 -1
2 3 1
5 3 1
5 2 1
5 2 4
5 2 4
3 2 4
3 2 4
3 5 4
3 5 2
Experiment No. 10
Experiment -10
Program Code:-
#include<stdio.h>
#include<conio.h>
intfr[3];
void main()
{
void display();
int p[12]={2,3,2,1,5,2,4,5,3,2,5,2},i,j,fs[3];
intindex,k,l,flag1=0,flag2=0,pf=0,frsize=3;
clrscr();
for(i=0;i<3;i++)
{
fr[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0,flag2=0;
for(i=0;i<3;i++)
{
if(fr[i]==p[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i<3;i++)
{
if(fr[i]==-1)
{
fr[i]=p[j];
flag2=1;
break;
}
}
}
if(flag2==0)
{
for(i=0;i<3;i++)
fs[i]=0;
for(k=j-1,l=1;l<=frsize-1;l++,k--)
{
for(i=0;i<3;i++)
{
if(fr[i]==p[k])
fs[i]=1;
}
}
for(i=0;i<3;i++)
{
if(fs[i]==0)
index=i;
}
fr[index]=p[j];
pf++;
}
display();
}
printf("\n no of page faults :%d",pf);
getch();
}
void display()
{
inti;
printf("\n");
for(i=0;i<3;i++)
printf("\t%d",fr[i]);
}
Program Output :
2 -1 -1
2 3 -1
2 3 -1
2 3 1
2 5 1
2 5 1
2 5 4
2 5 4
3 5 4
3 5 2
3 5 2
3 5 2
no of page faults : 4
Experiment No. 11
Experiment-11
Program Objective:-Simulation of Paging technique of Memory Management
Program Prerequisite:- Basic knowledge of C programming and Concept of related Operating
system algorithm
Program Code:-
#include<stdio.h>
#include<conio.h>
intmain()
{
intpage[10], pagetab[10], pframe[2][2], I,j;
int size, msize, cnt, t,k,pos,logadd,m=0;
intframeno;
long int l;
inti;
printf("\nEnter the memory size:");
scanf("%d", &msize);
printf("Enter the pase size:");
scanf("%d", &size);
cnt=(msize/size);
printf("\nEnter the logical page: ");
for(j=0;j
{
scanf("%d", &lpage[j]);
}
t=0;
k=0;
for(j=0;j
{
printf("\n");
if(t
{
printf("%d value is %d\n", t,lpage[j]);
t++;
}
else
{
t=0;
printf("%d value is %d\n", t,lpage[j]);
t++;
}
}
printf("\nEnter the page table value: ");
for(i=0;i
{
scanf("%d", &pagetab[i]);
}
printf("\nEnter the logical address: ");
scanf("%d", &logadd);
for(k=0;k
{
if(logadd==lpage[k])
{
pos=(k/size);
m=k%size;
break;
}
else
continue;
}
printf("\nPage number : %d", pos);
frameno=pagetab[pos];
printf("\nThe frame number is %d\n", frameno);
printf("\nThe corresponding physical address is %d", (frameno*size)+m);
}
Program Output:
Enter the memory size:4
Enter the page size:2
Enter the logical page: 2
3
4
5
0 value is 2
1 value is 3
0 value is 4
1 value is 5
Enter the page table value: 101
102
Enter the logical address: 5
Page number : 1
The frame number is 102
The corresponding physical address is 205
Experiment No. 12
Experiment 12
Objective :Calculation of external and internal fragmentation i. Free space list of blocks
from system ii. List process file from the system
SOURCE CODE:
#include<stdio.h> #include<conio.h> void main()
{
int m=0,m1=0,m2=0,p,count=0,i; clrscr();
printf("enter the memory capacity:"); scanf("%d",&m); printf("enter the no of processes:");
scanf("%d",&p); for(i=0;i<p;i++)
{
printf("\nenter memory req for process%d: ",i+1); scanf("%d",&m1); count=count+m1;
if(m1<=m)
{
if(count==m)
printf("there is no further memory remaining:");
printf("the memory allocated for process%d is: %d ",i+1,m);m2=m-m1; printf("\nremaining
memory is: %d",m2); m=m2;
}
}
else
{
printf("memory is not allocated for process%d",i+1);
}
printf("\nexternal fragmentation for this process is:%d",m2);
}
getch();
}
Step 3: calculate the number of partitions the total memory has to be divided.
Step 4: Get the required memory for each process if the required memory is available in that
particular partition the process will be allocated to that partition and the internal fragmentation will
be calculated.
Step 5: If the required memory not available then the process will not be allocated to that partition.
Step 6: Calculate the external fragmentation and total number of fragmentation.
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
intmain()
{
intm,p,s,p1;
int m1[4],i,f,f1=0,f2=0,fra1,fra2,s1,pos; clrscr();
printf("Enter the memory size:");
scanf("%d",&m);
printf("Enter the no of partitions:");
scanf("%d",&p); s=m/p;
printf("Each partn size is:%d",s);
printf("\nEnter the no of processes:");
scanf("%d",&p1); pos=m;
for(i=0;i<p1;i++)
{
if(pos<s)
{
printf("\nThere is no further memory for process%d",i+1); m1[i]=0; break;
}
else
{
printf("\nEnter the memory req for process%d:",i+1); scanf("%d",&m1[i]); if(m1[i]<=s)
{
printf("\nProcess is allocated in partition%d",i+1); fra1=s-m1[i]; printf("\nInternal fragmentation
for process is:%d",fra1); f1=f1+fra1; pos=pos-s;
}
else
{
printf("\nProcess not allocated in partition%d",i+1); s1=m1[i]; while(s1>s)
{
s1=s1-s;pos=pos-s;
}
pos=pos-s;fra2=s-s1;f2=f2+fra2;
printf("\nExternal Fragmentation for this process is:%d",fra2);
}
}
}
printf("\nProcess\tallocatedmemory");
for(i=0;i<p1;i++)
printf("\n%5d\t%5d",i+1,m1[i]);
f=f1+f2;
printf("\nThe tot no of fragmentation is:%d",f); getch(); return 0;
}
Output:
Process1 is allocated in partn1
Internal fragmentation for process1 is: 2 Enter the memory req for process2: 22 Process2 is not
allocated in partn2 External fragmentation for process2 is: 18
Experiment No. 13
Experiment :13
Implement file storage allocation technique: i. Contiguous(using array) ii. Linked –list(using
linked-list) iii. Indirect allocation (indexing)
OBJECTIVE:Toimplementsequentialfileallocationtechnique.
ALGORITHM:
Step1:Starttheprogram.
Step2:Getthe numberoffiles.
Step3:Getthememoryrequirementofeach file.
Step4:Allocatetherequiredlocationstoeachinsequentialorder.
a).Randomlyselectalocationfromavailablelocations1=random(100);b).
Check whether the required locations are free from the selected
SOURCECODE:
#include<stdio.h>
main()
{
intf[50],i,st,j,len,c,k;
clrscr();for(i=0;i<50;
i++)f[i]=0;
X:
printf("\n Enter the starting block & length of
file");scanf("%d%d",&st,&len);
for(j=st;j<(st+len);j+
+)if(f[j]==0)
{f[j]=
1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("Block already
allocated");break;
}
if(j==(st+len))
printf("\nthefileisallocatedtodisk");
printf("\n if u want to enter more files?(y-1/n-
0)");scanf("%d",&c);
if(c==1)
goto
X;elsee
xit();
getch();
}
Output:
Enterthestartingblock&lengthoffile 410
4->1
5->1
6->1
7->1
8->1
9->1
10->1
11->1
12->1
13->1
Thefileisallocatedtodisk
Ifyouwanttoentermorefiles?(Y-1/N-o)
LINKEDFILEALLOCATION
OBJECTIVE:
To write a C program to implement File Allocation concept using the technique Linked
ListTechnique.
ALGORITHM:
Step1:StarttheProgram
Step2:Getthenumberoffiles.
Step 5: If the location is free allocate and set flag =1 to the allocated
Step7:Stoptheexecution
SOURCECODE:
#include<stdio.h>
main()
{
intf[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i+
+)f[i]=0;
printf("Enter how many blocks that are already
allocated");scanf("%d",&p);
printf("\nEnter the blocks no.s that are already
allocated");for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("Enter the starting index block &
length");scanf("%d%d",&st,&len);
k=len;for(j=st;j<(k+s
t);j++)
{
if(f[j]==0)
{f[j]=
1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already
allocated",j);k++;
}
}
printf("\n If u want to enter one more file? (yes-1/no-
0)");scanf("%d",&c);
if(c==1)
goto
X;elsee
xit();
getch();}
OUTPUT:
Enterhowmany blocksarealreadyallocated3
Enter the blocks no’s that are already allocated4 7
9Enterthe startingindexblock &length 3
7
3-> 1
4-> File is already
allocated5->1
6->1
7-> File is already
allocated8->1
9-> File is already
allocated10->1
11->1
12->1
Ifuwanttoenteronemorefile?(yes-1/no-0)
INDEXEDFILEALLOCATION
OBJECTIVE:
indexedallocationTechnique
ALGORITHM:
Step1:StarttheProgram
Step2:Getthe numberoffiles.
Step3:Getthememoryrequirementofeach file.
Step7:Stoptheexecution.
SOURCECODE:
#include<stdio.h>
int
f[50],i,k,j,inde[50],n,c,count=0,p;ma
in()
{
clrscr();for(i=0;i
<50;i++)f[i]=0;
x:
printf("enter index block\
t");scanf("%d",&p);
if(f[p]==0)
{f[p]=
1;
printf("enter no of files on index\
t");scanf("%d",&n);
}
else
{
printf("Block already allocated\
n");goto x;
}
for(i=0;i<n;i+
+)scanf("%d",&inde[i
]);for(i=0;i<n;i+
+)if(f[inde[i]]==1)
{
printf("Block already
allocated");goto x;
}
for(j=0;j<n;j+
+)f[inde[j]]=1;printf(
"\nallocated");
printf("\n file
indexed");for(k=0;k<n;
k++)
printf("\n %d->%d:
%d",p,inde[k],f[inde[k]]);printf(" Enter 1 to enter
more files and 0 to exit\t");scanf("%d",&c);
if(c==1)
goto
x;elseex
it();
getch();
}
OUTPUT:
Enterindexblock9
Enterno offilesonindex
31 2 3
AllocatedFi
le indexed9-
> 1:1
9-> 2:1
9->3:1
Enter1toentermore filesand0 toexit
Experiment No. 14
Experiment 14 :SIMULATEBANKERSALGORITHMFORDEADLOCKAVOIDANCE
OBJECTIVE:
TowriteaCprogramtoimplementbankersalgorithmfordeadlockavoidance
ALGORITHM:
Step1:StarttheProgram
Step4:Afterallocationfindtheneedvalue.
Step5:Checkwhether itspossibletoallocate.Ifpossibleitissafestate
Step 6: If the new request comes then check that the system is in safety or not if we allow
therequest.
Step7:Stoptheexecution
SOURCECODE:
#include<stdio..h>
#include<conioh>
voidmain()
{
intn,r,i,j,k,p,u=0,s=0,m;
intblock[10],run[10],active[10],newreq[10];
intmax[10][10],resalloc[10][10],resreq[10][1];inttotalloc[10],totext[10],simalloc[10];
clrscr();
printf("Enter the no of processes:");scanf("%d",&n);
printf("Enter the no of resource classes:");scanf("%d",&r);
printf("Enter the total existed resource in each class:");for(k=1;k<=r;k++)
scanf("%d",&totext[k]);
printf("Enter the allocated resources:");
for(i=1;i<=n;i++)
for(k=1;k<=r;k++)
scanf("%d",&resallc);
printf("Enter the process making the new request:");
scanf("%d",&p);
printf("Enter the requested resource:");
for(k=1;k<=r;k++)scanf("%d",&newreq[k]);
printf("Enter the process which are n blocked or running:");
for(i=1;i<=n;i++)
{
if(i!=p)
{
printf("process %d:\n",i+1);scanf("%d%d",&block[i],&run[i]);
}}
block[p]=0;run[p]=0;for(k=1;k<=r;k)
{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;
elseactive[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]<=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("Deadlockwilln'toccur");
}
Else
{
for(k=1;k<=r;k++)
{
resalloc[p][k]=newreq[k];
totalloc[k]=newreq[k];
}
printf("Deadlockwilloccur");
}
getch();
}
OUTPUT:
Enterthenoofresources:4
Enterthenoofresourceclasses:3
Enter the total existed resources in each class: 3 2 2Enter the allocated resources: 1 0 0 5 1 1 2 1 1 0 0
2Enterthe processmaking the newrequest: 2
Entertherequestedresource:112
Enter the processes which are n blocked or running: Process 1: 1 2Process3: 10
Process 4: 1 0Deadlockwilloccur
Sample question for Viva-Voce
3. If the quantum time of round robin algorithm is very large, then it is equivalent to:
(A) First in first out
(B) Shortest Job Next
(C) Lottery scheduling
(D) None of the above
Answer: (A)
Round-robin:-round-robin policy is a method in which every process gets its time slice. after executing a
process for certain time slice..if the job is not completed in that time it will be thrown into waiting state
and the next job gets the timeslice and will be executed..and the process that was in waiting state will get
processor time after the remaining processes are completed.
14. Which of the following statements are true?
I. Shortest remaining time first scheduling may cause starvation
II. Preemptive scheduling may cause starvation
III. Round robin is better than FCFS in terms of response time
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III
Answer: (D)
15. What is basic idea behind LRU
A good approximation to the optimal algorithm is based on the observation that pages that have been
heavily used in the last few instructions will probably be heavily used again in the next few. Conversely,
pages that have not been used for ages will probably remain unused for a long time. This idea suggests a
realizable algorithm: when a page fault occurs, throw out the page that has been unused for the longest
time. This strategy is called LRU (Least Recently Used) paging.
20. Logical memory is broken into blocks of the same size called _________.
a) frames
b) pages
c) backing store
d) None of these
Answer: b
21. Every address generated by the CPU is divided into two parts : (choose two)
a) frame bit
b) page number
c) page offset
d) frame offset
Answer: b and c
22. The _____ table contains the base address of each page in physical memory.
a) process
b) memory
c) page
d) frame
Answer: c