SlideShare a Scribd company logo
1 of 20
Download to read offline
OS LAB MANUAL

                MURALI




         OS Lab Manual


Operating Systems

                K.MURALI

    COMPUTER SCIENCE AND ENGINEERING

    GUDLAVALLERU ENGINEERING COLLEGE




               CSE ROCKS
OS LAB MANUAL

                                            MURALI

1) Simulate the following CPU scheduling algorithms
     a) FCFS
     b) SJF
     c) Priority
     d) Round Robin

a) FCFS:
AIM : A program to simulate the FCFS CPU scheduling algorithm

PROGRAM:

#include<stdio.h>
#include<string.h>
#include<conio.h>
main()
{
char pn[10][10],t[10];
int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,j,n,temp;
int totwt=0,tottat=0;
//clrscr();
printf("Enter the number of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Process Name, Arrival Time & Burst Time:");
scanf("%s%d%d",&pn[i],&arr[i],&bur[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
temp=bur[i];
bur[i]=bur[j];
bur[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}


                                                                     4




                                           CSE ROCKS
OS LAB MANUAL

                                          MURALI

}
for(i=0;i<n;i++)
{
if(i==0)
star[i]=arr[i];
else
star[i]=finish[i-1];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];
}
printf("nPName Arrtime Burtime WaitTime Start TAT Finish");
for(i=0;i<n;i++)
{
printf("n%st%3dt%3dt%3dt%3dt%6dt%6d",pn[i],arr[i],bur[i],wt[i],star[i],tat[i],finis
h[i]);
totwt+=wt[i];
tottat+=tat[i];
}
printf("nAverage Waiting time:%f",(float)totwt/n);
printf("nAverage Turn Around Time:%f",(float)tottat/n);
getch();
return 0;
}
OUTPUT:

Input:

Enter the number of processes: 3
Enter the Process Name, Arrival Time & Burst Time: p1 2 4
Enter the Process Name, Arrival Time & Burst Time: p2 3 5
Enter the Process Name, Arrival Time & Burst Time: p3 1 6

Output:

PName Arrtime Burtime WaitTime                  Srart TAT Finish
p3    1     6 0   1 6 7
p1    2    4 5  7 9 11
p2    3    5 8  11 13 16

Average Waiting Time: 4.3333333
Average Turn Around Time: 9.33333333




                                         CSE ROCKS
OS LAB MANUAL

                                          MURALI

b) SJF:
AIM: A program to simulate the SJF CPU scheduling algorithm

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
clrscr();
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter process name, arrival time & execution time:");
flushall();
scanf("%s%d%d",pn[i],&at[i],&et[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(et[i]<et[j])
{
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
for(i=0;i<n;i++)
{
if(i==0)
st[i]=at[i];
else
st[i]=ft[i-1];




                                         CSE ROCKS
OS LAB MANUAL

                                            MURALI

wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
totwt+=wt[i];
totta+=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("nPnametarrivaltimetexecutiontimetwaitingtimettatime");
for(i=0;i<n;i++)
printf("n%st%5dtt%5dtt%5dtt%5d",pn[i],at[i],et[i],wt[i],ta[i]);
printf("nAverage waiting time is:%f",awt);
printf("nAverage turnaroundtime is:%f",ata);
getch();
}

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




                                                                          7




                                           CSE ROCKS
OS LAB MANUAL

                                          MURALI

c) Priority:

AIM: A program to simulate the priority CPU scheduling algorithm

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
clrscr();
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter process name,arrivaltime,execution time & priority:");
flushall();
scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(p[i]<p[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
for(i=0;i<n;i++)
{




                                         CSE ROCKS
OS LAB MANUAL

                                            MURALI

if(i==0)
{
st[i]=at[i];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
}
else
{
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
}
totwt+=wt[i];
totta+=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("nPnametarrivaltimetexecutiontimetprioritytwaitingtimettatime");
for(i=0;i<n;i++)
printf("n%st%5dtt%5dtt%5dtt%5dtt%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]);
printf("nAverage waiting time is:%f",awt);
printf("nAverage turnaroundtime is:%f",ata);
getch();
}

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:

Pname   arrivaltime executiontime          priority     waitingtime      tatime
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




                                           CSE ROCKS
OS LAB MANUAL

                                        MURALI

d) Round Robin:
AIM: 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);
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: %sn",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;}
}




                                       CSE ROCKS
OS LAB MANUAL

                                           MURALI

}
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




                                          CSE ROCKS
OS LAB MANUAL

                                          MURALI

2) Simulate the MVT and MFT.

MVT:
AIM: A program to simulate the MVT.

PROGRAM:

#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();

}




                                         CSE ROCKS
OS LAB MANUAL

                                           MURALI

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: 80
Remaining memory is: 57
External fragmentation for this process is: 57
Enter memory req for process2: 52
The memory allocated for process2 is: 57
Remaining memory is: 5
External fragmentation for this process is: 5




                                          CSE ROCKS
OS LAB MANUAL

                                     MURALI

MFT:
AIM: A Program to simulate the MFT

PROGRAM:

#include<stdio.h>
#include<conio.h>
int main()
{
int m,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 alloca ted in partition%d",i+1);
fra1=s-m1[i];
printf("nInternal fragmentation for process is:%d",fra1);
f1=f1+fra1;
pos=pos-s;




                                   CSE ROCKS
OS LAB MANUAL

                                    MURALI

}
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("nProcesstallocatedmemory");
for(i=0;i<p1;i++)
printf("n%5dt%5d",i+1,m1[i]);
f=f1+f2;
printf("nThe tot no of fragmentation is:%d",f);
getch();
return 0;
}




                                   CSE ROCKS
OS LAB MANUAL

                                             MURALI

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
Process2 is not allocated in partn2
External fragmentation for process2 is: 18

Process         memory               allocated
1             20   18
2                  20                        22

The tot no of fragmentation is: 20




                                           CSE ROCKS
OS LAB MANUAL

                                            MURALI

3) Simulate all Page Replacement Algorithms
   a) FIFO
   b) LRU

a) FIFO:
AIM: A program to simulate FIFO Page Replacement Algorithm

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
clrscr();
printf("Enter the Number of Pages:");
scanf("%d",&n);
printf("Enter %d Page Numbers:",n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
}
}
printf("n%d",b[i]);
printf("t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
p=0;
for(k=0;k<q1;k++)




                                           CSE ROCKS
OS LAB MANUAL

                                    MURALI

{
if(b[i+1]==a[k])
p=1;
}
}
printf("nNo of faults:%d",m);
getch();
}
OUTPUT:

Input:

Enter the Number of Pages: 12
Enter 12 Page Numbers:
232152453252

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




                                   CSE ROCKS
OS LAB MANUAL

                                         MURALI

b) LRU:
AIM: A program to simulate LRU Page Replacement Algorithm

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int g=0,a[5],b[20],p=0,q=0,m=0,h,k,i,q1=1,j,u,n;
char f='F';
clrscr();
printf("Enter the number of pages:");
scanf("%d",&n);
printf("Enter %d Page Numbers:",n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
//g=1;
}
}
printf("n%d",b[i]);
printf("t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
p=0;
g=0;
if(q1==3)
{
for(k=0;k<q1;k++)
{




                                        CSE ROCKS
OS LAB MANUAL

                                    MURALI

if(b[i+1]==a[k])
p=1;
}
for(j=0;j<q1;j++)
{
u=0;
k=i;
while(k>=(i-1)&&(k>=0))
{
if(b[k]==a[j])
u++;
k--;
}
if(u==0)
q=j;
}
}
else
{
for(k=0;k<q;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
}
printf("nNo of faults:%d",m);
getch();
}




                                   CSE ROCKS
OS LAB MANUAL

                                   MURALI

OUTPUT:

Input:

Enter the Number of Pages: 12
Enter 12 Page Numbers:
232152453252

Output:

2   2-> F
3   23-> F
2   23
1   231-> F
5   251-> F
2   251
4   254-> F
5   254
3   354-> F
2   352-> F
5   352
2   352

No of faults: 7




                                  CSE ROCKS
OS LAB MANUAL

                                             MURALI

4) Simulate Paging technique of Memory Management.

AIM: A program to simulate Paging technique of memory management.

PROGRAM:

#include<stdio.h>
#include<conio.h>
main()
{
int np,ps,i;
int *sa;
clrscr();
printf("enter how many pagesn");
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%dt address %un",i+1,sa[i]);
}
getch();
}

OUTPUT:

Input:

Enter how many pages: 5
Enter the page size: 4

Output:

Page1 Address: 1894
Page2 Address: 1902
Page3 Address: 1910
Page4 Address: 1918
Page5 Address: 1926




                                         CSE ROCKS

More Related Content

What's hot

Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Stringsvinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)vinay arora
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structuresvinay arora
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Treeraviahuja11
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C ProgramsKandarp Tiwari
 
C basics
C basicsC basics
C basicsMSc CST
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programsAnanda Kumar HN
 
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollideropenFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperColliderAtsushi Tadokoro
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointersSushil Mishra
 

What's hot (20)

Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
C Prog - Strings
C Prog - StringsC Prog - Strings
C Prog - Strings
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 
C programms
C programmsC programms
C programms
 
C Prog. - Structures
C Prog. - StructuresC Prog. - Structures
C Prog. - Structures
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
C basics
C basicsC basics
C basics
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Double linked list
Double linked listDouble linked list
Double linked list
 
C programs
C programsC programs
C programs
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollideropenFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
openFrameworks、サウンド機能・音響合成、ofxMaxim, ofxOsc, ofxPd, ofxSuperCollider
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 

Viewers also liked

Highlighting the people factor; analyzing how a Social Base impacts Economic ...
Highlighting the people factor; analyzing how a Social Base impacts Economic ...Highlighting the people factor; analyzing how a Social Base impacts Economic ...
Highlighting the people factor; analyzing how a Social Base impacts Economic ...Jose Daniel Covarrubias
 
World english unit 1,2,3
World english unit 1,2,3World english unit 1,2,3
World english unit 1,2,3joisgiraldo
 
Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...
Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...
Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...Jose Daniel Covarrubias
 
Atlas de parasitologia médica color con orientación clinica
Atlas de parasitologia médica color con orientación clinicaAtlas de parasitologia médica color con orientación clinica
Atlas de parasitologia médica color con orientación clinicaMelany Gallardo
 
Regional Studies Association Public Policy Learning Workshop
Regional Studies Association Public Policy Learning WorkshopRegional Studies Association Public Policy Learning Workshop
Regional Studies Association Public Policy Learning WorkshopJose Daniel Covarrubias
 
World english unit 1,2,3
World english unit 1,2,3World english unit 1,2,3
World english unit 1,2,3joisgiraldo
 
Bridging the gap: Socially integrating cross-border regions, comparing differ...
Bridging the gap: Socially integrating cross-border regions, comparing differ...Bridging the gap: Socially integrating cross-border regions, comparing differ...
Bridging the gap: Socially integrating cross-border regions, comparing differ...Jose Daniel Covarrubias
 

Viewers also liked (14)

University
UniversityUniversity
University
 
Highlighting the people factor; analyzing how a Social Base impacts Economic ...
Highlighting the people factor; analyzing how a Social Base impacts Economic ...Highlighting the people factor; analyzing how a Social Base impacts Economic ...
Highlighting the people factor; analyzing how a Social Base impacts Economic ...
 
Programs
ProgramsPrograms
Programs
 
Programs
ProgramsPrograms
Programs
 
World english unit 1,2,3
World english unit 1,2,3World english unit 1,2,3
World english unit 1,2,3
 
Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...
Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...
Highlighting the People Factor; Analyzing how a Social Base impacts Economic ...
 
Vocabulary
VocabularyVocabulary
Vocabulary
 
Atlas de parasitologia médica color con orientación clinica
Atlas de parasitologia médica color con orientación clinicaAtlas de parasitologia médica color con orientación clinica
Atlas de parasitologia médica color con orientación clinica
 
Nielsen social-media-report
Nielsen social-media-reportNielsen social-media-report
Nielsen social-media-report
 
Os lab upto 1st mid
Os lab upto 1st midOs lab upto 1st mid
Os lab upto 1st mid
 
Regional Studies Association Public Policy Learning Workshop
Regional Studies Association Public Policy Learning WorkshopRegional Studies Association Public Policy Learning Workshop
Regional Studies Association Public Policy Learning Workshop
 
False cognates
False cognatesFalse cognates
False cognates
 
World english unit 1,2,3
World english unit 1,2,3World english unit 1,2,3
World english unit 1,2,3
 
Bridging the gap: Socially integrating cross-border regions, comparing differ...
Bridging the gap: Socially integrating cross-border regions, comparing differ...Bridging the gap: Socially integrating cross-border regions, comparing differ...
Bridging the gap: Socially integrating cross-border regions, comparing differ...
 

Similar to Os lab upto_1st_mid

Similar to Os lab upto_1st_mid (20)

Operating system labs
Operating system labsOperating system labs
Operating system labs
 
Unix Programs
Unix ProgramsUnix Programs
Unix Programs
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
System Software/Operating Sytems lab report
System Software/Operating Sytems lab reportSystem Software/Operating Sytems lab report
System Software/Operating Sytems lab report
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Lab9 LRU and FIFO.docx
Lab9 LRU and FIFO.docxLab9 LRU and FIFO.docx
Lab9 LRU and FIFO.docx
 
week-3x
week-3xweek-3x
week-3x
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Bankers Algo Implementation
Bankers Algo ImplementationBankers Algo Implementation
Bankers Algo Implementation
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
week-5x
week-5xweek-5x
week-5x
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
Let us C (by yashvant Kanetkar) chapter 3 Solution
Let us C   (by yashvant Kanetkar) chapter 3 SolutionLet us C   (by yashvant Kanetkar) chapter 3 Solution
Let us C (by yashvant Kanetkar) chapter 3 Solution
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C file
C fileC file
C file
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Hargun
HargunHargun
Hargun
 
Structure
StructureStructure
Structure
 

Recently uploaded

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 

Recently uploaded (20)

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 

Os lab upto_1st_mid

  • 1. OS LAB MANUAL MURALI OS Lab Manual Operating Systems K.MURALI COMPUTER SCIENCE AND ENGINEERING GUDLAVALLERU ENGINEERING COLLEGE CSE ROCKS
  • 2. OS LAB MANUAL MURALI 1) Simulate the following CPU scheduling algorithms a) FCFS b) SJF c) Priority d) Round Robin a) FCFS: AIM : A program to simulate the FCFS CPU scheduling algorithm PROGRAM: #include<stdio.h> #include<string.h> #include<conio.h> main() { char pn[10][10],t[10]; int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,j,n,temp; int totwt=0,tottat=0; //clrscr(); printf("Enter the number of processes:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the Process Name, Arrival Time & Burst Time:"); scanf("%s%d%d",&pn[i],&arr[i],&bur[i]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(arr[i]<arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; temp=bur[i]; bur[i]=bur[j]; bur[j]=temp; strcpy(t,pn[i]); strcpy(pn[i],pn[j]); strcpy(pn[j],t); } } 4 CSE ROCKS
  • 3. OS LAB MANUAL MURALI } for(i=0;i<n;i++) { if(i==0) star[i]=arr[i]; else star[i]=finish[i-1]; wt[i]=star[i]-arr[i]; finish[i]=star[i]+bur[i]; tat[i]=finish[i]-arr[i]; } printf("nPName Arrtime Burtime WaitTime Start TAT Finish"); for(i=0;i<n;i++) { printf("n%st%3dt%3dt%3dt%3dt%6dt%6d",pn[i],arr[i],bur[i],wt[i],star[i],tat[i],finis h[i]); totwt+=wt[i]; tottat+=tat[i]; } printf("nAverage Waiting time:%f",(float)totwt/n); printf("nAverage Turn Around Time:%f",(float)tottat/n); getch(); return 0; } OUTPUT: Input: Enter the number of processes: 3 Enter the Process Name, Arrival Time & Burst Time: p1 2 4 Enter the Process Name, Arrival Time & Burst Time: p2 3 5 Enter the Process Name, Arrival Time & Burst Time: p3 1 6 Output: PName Arrtime Burtime WaitTime Srart TAT Finish p3 1 6 0 1 6 7 p1 2 4 5 7 9 11 p2 3 5 8 11 13 16 Average Waiting Time: 4.3333333 Average Turn Around Time: 9.33333333 CSE ROCKS
  • 4. OS LAB MANUAL MURALI b) SJF: AIM: A program to simulate the SJF CPU scheduling algorithm PROGRAM: #include<stdio.h> #include<conio.h> #include<string.h> void main() { int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10]; int totwt=0,totta=0; float awt,ata; char pn[10][10],t[10]; clrscr(); printf("Enter the number of process:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter process name, arrival time & execution time:"); flushall(); scanf("%s%d%d",pn[i],&at[i],&et[i]); } for(i=0;i<n;i++) for(j=0;j<n;j++) { if(et[i]<et[j]) { temp=at[i]; at[i]=at[j]; at[j]=temp; temp=et[i]; et[i]=et[j]; et[j]=temp; strcpy(t,pn[i]); strcpy(pn[i],pn[j]); strcpy(pn[j],t); } } for(i=0;i<n;i++) { if(i==0) st[i]=at[i]; else st[i]=ft[i-1]; CSE ROCKS
  • 5. OS LAB MANUAL MURALI wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; totwt+=wt[i]; totta+=ta[i]; } awt=(float)totwt/n; ata=(float)totta/n; printf("nPnametarrivaltimetexecutiontimetwaitingtimettatime"); for(i=0;i<n;i++) printf("n%st%5dtt%5dtt%5dtt%5d",pn[i],at[i],et[i],wt[i],ta[i]); printf("nAverage waiting time is:%f",awt); printf("nAverage turnaroundtime is:%f",ata); getch(); } 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 7 CSE ROCKS
  • 6. OS LAB MANUAL MURALI c) Priority: AIM: A program to simulate the priority CPU scheduling algorithm PROGRAM: #include<stdio.h> #include<conio.h> #include<string.h> void main() { int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10]; int totwt=0,totta=0; float awt,ata; char pn[10][10],t[10]; clrscr(); printf("Enter the number of process:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter process name,arrivaltime,execution time & priority:"); flushall(); scanf("%s%d%d%d",pn[i],&at[i],&et[i],&p[i]); } for(i=0;i<n;i++) for(j=0;j<n;j++) { if(p[i]<p[j]) { temp=p[i]; p[i]=p[j]; p[j]=temp; temp=at[i]; at[i]=at[j]; at[j]=temp; temp=et[i]; et[i]=et[j]; et[j]=temp; strcpy(t,pn[i]); strcpy(pn[i],pn[j]); strcpy(pn[j],t); } } for(i=0;i<n;i++) { CSE ROCKS
  • 7. OS LAB MANUAL MURALI if(i==0) { st[i]=at[i]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; } else { st[i]=ft[i-1]; wt[i]=st[i]-at[i]; ft[i]=st[i]+et[i]; ta[i]=ft[i]-at[i]; } totwt+=wt[i]; totta+=ta[i]; } awt=(float)totwt/n; ata=(float)totta/n; printf("nPnametarrivaltimetexecutiontimetprioritytwaitingtimettatime"); for(i=0;i<n;i++) printf("n%st%5dtt%5dtt%5dtt%5dtt%5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]); printf("nAverage waiting time is:%f",awt); printf("nAverage turnaroundtime is:%f",ata); getch(); } 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: Pname arrivaltime executiontime priority waitingtime tatime 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 CSE ROCKS
  • 8. OS LAB MANUAL MURALI d) Round Robin: AIM: 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); 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: %sn",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;} } CSE ROCKS
  • 9. OS LAB MANUAL MURALI } 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 CSE ROCKS
  • 10. OS LAB MANUAL MURALI 2) Simulate the MVT and MFT. MVT: AIM: A program to simulate the MVT. PROGRAM: #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(); } CSE ROCKS
  • 11. OS LAB MANUAL MURALI 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: 80 Remaining memory is: 57 External fragmentation for this process is: 57 Enter memory req for process2: 52 The memory allocated for process2 is: 57 Remaining memory is: 5 External fragmentation for this process is: 5 CSE ROCKS
  • 12. OS LAB MANUAL MURALI MFT: AIM: A Program to simulate the MFT PROGRAM: #include<stdio.h> #include<conio.h> int main() { int m,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 alloca ted in partition%d",i+1); fra1=s-m1[i]; printf("nInternal fragmentation for process is:%d",fra1); f1=f1+fra1; pos=pos-s; CSE ROCKS
  • 13. OS LAB MANUAL MURALI } 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("nProcesstallocatedmemory"); for(i=0;i<p1;i++) printf("n%5dt%5d",i+1,m1[i]); f=f1+f2; printf("nThe tot no of fragmentation is:%d",f); getch(); return 0; } CSE ROCKS
  • 14. OS LAB MANUAL MURALI 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 Process2 is not allocated in partn2 External fragmentation for process2 is: 18 Process memory allocated 1 20 18 2 20 22 The tot no of fragmentation is: 20 CSE ROCKS
  • 15. OS LAB MANUAL MURALI 3) Simulate all Page Replacement Algorithms a) FIFO b) LRU a) FIFO: AIM: A program to simulate FIFO Page Replacement Algorithm PROGRAM: #include<stdio.h> #include<conio.h> void main() { int a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1; char f='F'; clrscr(); printf("Enter the Number of Pages:"); scanf("%d",&n); printf("Enter %d Page Numbers:",n); for(i=0;i<n;i++) scanf("%d",&b[i]); for(i=0;i<n;i++) {if(p==0) { if(q>=3) q=0; a[q]=b[i]; q++; if(q1<3) { q1=q; } } printf("n%d",b[i]); printf("t"); for(h=0;h<q1;h++) printf("%d",a[h]); if((p==0)&&(q<=3)) { printf("-->%c",f); m++; } p=0; for(k=0;k<q1;k++) CSE ROCKS
  • 16. OS LAB MANUAL MURALI { if(b[i+1]==a[k]) p=1; } } printf("nNo of faults:%d",m); getch(); } OUTPUT: Input: Enter the Number of Pages: 12 Enter 12 Page Numbers: 232152453252 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 CSE ROCKS
  • 17. OS LAB MANUAL MURALI b) LRU: AIM: A program to simulate LRU Page Replacement Algorithm PROGRAM: #include<stdio.h> #include<conio.h> void main() { int g=0,a[5],b[20],p=0,q=0,m=0,h,k,i,q1=1,j,u,n; char f='F'; clrscr(); printf("Enter the number of pages:"); scanf("%d",&n); printf("Enter %d Page Numbers:",n); for(i=0;i<n;i++) scanf("%d",&b[i]); for(i=0;i<n;i++) {if(p==0) { if(q>=3) q=0; a[q]=b[i]; q++; if(q1<3) { q1=q; //g=1; } } printf("n%d",b[i]); printf("t"); for(h=0;h<q1;h++) printf("%d",a[h]); if((p==0)&&(q<=3)) { printf("-->%c",f); m++; } p=0; g=0; if(q1==3) { for(k=0;k<q1;k++) { CSE ROCKS
  • 18. OS LAB MANUAL MURALI if(b[i+1]==a[k]) p=1; } for(j=0;j<q1;j++) { u=0; k=i; while(k>=(i-1)&&(k>=0)) { if(b[k]==a[j]) u++; k--; } if(u==0) q=j; } } else { for(k=0;k<q;k++) { if(b[i+1]==a[k]) p=1; } } } printf("nNo of faults:%d",m); getch(); } CSE ROCKS
  • 19. OS LAB MANUAL MURALI OUTPUT: Input: Enter the Number of Pages: 12 Enter 12 Page Numbers: 232152453252 Output: 2 2-> F 3 23-> F 2 23 1 231-> F 5 251-> F 2 251 4 254-> F 5 254 3 354-> F 2 352-> F 5 352 2 352 No of faults: 7 CSE ROCKS
  • 20. OS LAB MANUAL MURALI 4) Simulate Paging technique of Memory Management. AIM: A program to simulate Paging technique of memory management. PROGRAM: #include<stdio.h> #include<conio.h> main() { int np,ps,i; int *sa; clrscr(); printf("enter how many pagesn"); 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%dt address %un",i+1,sa[i]); } getch(); } OUTPUT: Input: Enter how many pages: 5 Enter the page size: 4 Output: Page1 Address: 1894 Page2 Address: 1902 Page3 Address: 1910 Page4 Address: 1918 Page5 Address: 1926 CSE ROCKS