SlideShare a Scribd company logo
1 of 8
To implement the concept of interprocess communication using pipes using c
program.
#include<stdio.h>
#include<unistd.h>
#include<string.h>
main()
{
int p1[2],p2[2],p3[2],p4[2];
int i,j=0,k=0,l=0;
char r[10],s[10],t[10],u[10];
printf("t PROCESS 1.ENTER THE STRING");
scanf("%s",r);
pipe(p1);
pipe(p2);
write(p1[1],r,sizeof(r));
write(p2[1],r,sizeof(r));
int a=fork();
if(a==0)
{
printf("nt PROCESS 2:it splits the given stringn");
read(p1[0],r,sizeof(r));
int n=strlen(r);
for(i=0;i<n/2;i++)
{
s[i]=r[i];
}
for(i=n/2;i<=n;i++)
{
t[j++]=r[i];
}
pipe(p3);
pipe(p4);
write(p3[1],s,sizeof(s));
write(p4[1],t,sizeof(t));
int b=fork();
if(b==0)
{
printf("p4 %dt",getpid());
printf("p2 %dn",getppid());
read(p3[0],s,sizeof(s));
printf("t PROCESS 4:sub string t %s t",s);
printf("no of char=%d n",strlen(s));
}
else
{
int c=fork();
if(c==0)
{
printf("p5 %dt",getpid());
printf("p2 %dn",getppid());
read(p4[0],t,sizeof(t));
printf("t PROCESS 5:sub string t %s t",t);
printf("no of char=%d n",strlen(t));
}
else
{
wait();
printf("p2 %dt",getpid());
printf("p1 %dn",getppid());
} }}
else
{
wait();
int d=fork();
if(d==0)
{
printf("p3 %dt",getpid());
printf("p1 %dn",getppid());
read(p2[0],r,sizeof(r));
for(i=strlen(r)-1;i>=0;i--)
{
u[l++]=r[i];
}
for(i=0;i<strlen(r);i++)
{
if(u[i]==r[i])
k++;
else
continue;
}
if(k==strlen(r))
printf("t PROCESS 3: the given string is palindromen");
else
printf("t PROCESS 3: the given string is not palindromen");
}
else
{
printf("p1 %dt",getpid());
printf("kernal %dtn",getppid());
}
}
}
To write aprogram to implement the FCFS scheduling algorithm
#include<stdio.h>
main()
{
int n,a[10],b[10],t[10],w[10],g[10],i,m;
float att=0,awt=0;
for(i=0;i<10;i++)
{
a[i]=0; b[i]=0; w[i]=0; g[i]=0;
}
printf("enter the number of process");
scanf("%d",&n);
printf("enter the burst times");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
printf("nenter the arrival times");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
g[0]=0;
for(i=0;i<10;i++)
g[i+1]=g[i]+b[i];
for(i=0;i<n;i++)
{
w[i]=g[i]-a[i];
t[i]=g[i+1]-a[i];
awt=awt+w[i];
att=att+t[i];
}
awt =awt/n;
att=att/n;
printf("ntprocesstwaiting timetturn arround timen");
for(i=0;i<n;i++)
{
printf("tp%dtt%dtt%dn",i,w[i],t[i]);
}
printf("the average waiting time is %fn",awt);
printf("the average turn around time is %fn",att);
}
c program for round robinnon preemptive cpuscheduling algorithm
#include<stdio.h>
void main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);
printf("nEnter Burst Time:n");
for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1; //contains process number
}
//sorting burst time in ascending order using selection sort
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0; //waiting time for first process will be zero
//calculate waiting time
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=(float)total/n; //average waiting time
total=0;
printf("nProcesst Burst Time tWaiting TimetTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("np%dtt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n; //average turnaround time
printf("nnAverage Waiting Time=%f",avg_wt);
printf("nAverage Turnaround Time=%fn",avg_tat);
}
write a c program to implement FIFO page replacement algorithm
#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 stringt page framesn");
for(i=1;i<=n;i++)
{
printf("%dtt",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("%dt",frame[k]);
}
printf("n");
}
printf("Page Fault Is %d",count);
return 0;
}
To write ac program to implement LRUpage replacement algorithm
#include<stdio.h>
main()
{
int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20];
printf("Enter no of pages:");
scanf("%d",&n);
printf("Enter the reference string:");
for(i=0;i<n;i++)
scanf("%d",&p[i]);
printf("Enter no of frames:");
scanf("%d",&f);
q[k]=p[k];
printf("nt%dn",q[k]);
c++;
k++;
for(i=1;i<n;i++)
{
c1=0;
for(j=0;j<f;j++)
{
if(p[i]!=q[j])
c1++;
}
if(c1==f)
{
c++;
if(k<f)
{
q[k]=p[i];
k++;
for(j=0;j<k;j++)
printf("t%d",q[j]);
printf("n");
}
else
{
for(r=0;r<f;r++)
{
c2[r]=0;
for(j=i-1;j<n;j--)
{
if(q[r]!=p[j])
c2[r]++;
else
break;
}
}
for(r=0;r<f;r++)
b[r]=c2[r];
for(r=0;r<f;r++)
{
for(j=r;j<f;j++)
{
if(b[r]<b[j])
{
t=b[r];
b[r]=b[j];
b[j]=t;
}
}
}
for(r=0;r<f;r++)
{
if(c2[r]==b[0])
q[r]=p[i];
printf("t%d",q[r]);
}
printf("n");
}
}
}
printf("nThe no of page faults is %d",c);
}

More Related Content

What's hot

ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
kramsri
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
vrgokila
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
LPU
 

What's hot (17)

Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
test
testtest
test
 
Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
 
บทที่ 3
บทที่ 3บทที่ 3
บทที่ 3
 
Tools.cpp
Tools.cppTools.cpp
Tools.cpp
 
Session07 recursion
Session07 recursionSession07 recursion
Session07 recursion
 
Groovify your java code by hervé roussel
Groovify your java code by hervé rousselGroovify your java code by hervé roussel
Groovify your java code by hervé roussel
 
C programming on the determination of shear force, bending moment, shear stre...
C programming on the determination of shear force, bending moment, shear stre...C programming on the determination of shear force, bending moment, shear stre...
C programming on the determination of shear force, bending moment, shear stre...
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
Os lab 1st mid
Os lab 1st midOs lab 1st mid
Os lab 1st mid
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
 
Unix Programs
Unix ProgramsUnix Programs
Unix Programs
 
C programming
C programmingC programming
C programming
 
Forkexpe
ForkexpeForkexpe
Forkexpe
 
C & Python Introduction
C & Python IntroductionC & Python Introduction
C & Python Introduction
 

Viewers also liked

Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...
Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...
Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...
windi silviana
 

Viewers also liked (9)

Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...
Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...
Sim, windi silviana, hapzi ali, sistem pengambilan keputusan, universitas mer...
 
Adliner Anews 2017
Adliner Anews 2017Adliner Anews 2017
Adliner Anews 2017
 
Making a lesson plan
Making a lesson planMaking a lesson plan
Making a lesson plan
 
3Com 655000201
3Com 6550002013Com 655000201
3Com 655000201
 
Calendario Ass. Mon'Do'
Calendario Ass. Mon'Do'Calendario Ass. Mon'Do'
Calendario Ass. Mon'Do'
 
Opinionway pour l'Agence du Don en Nature - Générosité et consommation / Mars...
Opinionway pour l'Agence du Don en Nature - Générosité et consommation / Mars...Opinionway pour l'Agence du Don en Nature - Générosité et consommation / Mars...
Opinionway pour l'Agence du Don en Nature - Générosité et consommation / Mars...
 
Цитатна доріжка
 Цитатна доріжка Цитатна доріжка
Цитатна доріжка
 
Jmmatthewslaw
JmmatthewslawJmmatthewslaw
Jmmatthewslaw
 
Deep freezer
Deep freezerDeep freezer
Deep freezer
 

Similar to Os scheduling Algorithms

Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
riturajj
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
gkgaur1987
 
C basics
C basicsC basics
C basics
MSc CST
 

Similar to Os scheduling Algorithms (20)

programs
programsprograms
programs
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
 
Cd practical file (1) start se
Cd practical file (1) start seCd practical file (1) start se
Cd practical file (1) start se
 
Lecture 1 string functions
Lecture 1  string functionsLecture 1  string functions
Lecture 1 string functions
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
C basics
C basicsC basics
C basics
 
C Programming
C ProgrammingC Programming
C Programming
 
Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1Bcsl 033 data and file structures lab s1-1
Bcsl 033 data and file structures lab s1-1
 
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docxShad_Cryptography_PracticalFile_IT_4th_Year (1).docx
Shad_Cryptography_PracticalFile_IT_4th_Year (1).docx
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Common problems solving using c
Common problems solving using cCommon problems solving using c
Common problems solving using c
 
c programs.pptx
c programs.pptxc programs.pptx
c programs.pptx
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2Bcsl 033 data and file structures lab s2-2
Bcsl 033 data and file structures lab s2-2
 
Implementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & CImplementing Virtual Machines in Go & C
Implementing Virtual Machines in Go & C
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 

More from Neelamani Samal

A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...
A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...
A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...
Neelamani Samal
 

More from Neelamani Samal (16)

Fault Tolerance token Based Algorithm
Fault Tolerance token Based AlgorithmFault Tolerance token Based Algorithm
Fault Tolerance token Based Algorithm
 
RTS Question Paper 2012
RTS Question Paper 2012RTS Question Paper 2012
RTS Question Paper 2012
 
A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...
A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...
A fault tolerant tokenbased atomic broadcast algorithm relying on responsive ...
 
Os lab manual
Os lab manualOs lab manual
Os lab manual
 
computer architecture lab manual
computer architecture lab manualcomputer architecture lab manual
computer architecture lab manual
 
Software Engineering Sample Question paper for 2012
Software Engineering Sample Question paper for 2012Software Engineering Sample Question paper for 2012
Software Engineering Sample Question paper for 2012
 
Software Engineering Lab Manual
Software Engineering Lab ManualSoftware Engineering Lab Manual
Software Engineering Lab Manual
 
Software engineering note
Software engineering noteSoftware engineering note
Software engineering note
 
Values oflife
Values oflifeValues oflife
Values oflife
 
Attitute
AttituteAttitute
Attitute
 
Cd writning technology
Cd writning technologyCd writning technology
Cd writning technology
 
Turing machine
Turing machineTuring machine
Turing machine
 
Lamport’s algorithm for mutual exclusion
Lamport’s algorithm for mutual exclusionLamport’s algorithm for mutual exclusion
Lamport’s algorithm for mutual exclusion
 
How to install windows Xp sp2
How to install windows Xp sp2How to install windows Xp sp2
How to install windows Xp sp2
 
Game Playing In A I Final
Game  Playing In  A I  FinalGame  Playing In  A I  Final
Game Playing In A I Final
 
Computer Brain Power
Computer Brain PowerComputer Brain Power
Computer Brain Power
 

Recently uploaded

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 

Recently uploaded (20)

School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 

Os scheduling Algorithms

  • 1. To implement the concept of interprocess communication using pipes using c program. #include<stdio.h> #include<unistd.h> #include<string.h> main() { int p1[2],p2[2],p3[2],p4[2]; int i,j=0,k=0,l=0; char r[10],s[10],t[10],u[10]; printf("t PROCESS 1.ENTER THE STRING"); scanf("%s",r); pipe(p1); pipe(p2); write(p1[1],r,sizeof(r)); write(p2[1],r,sizeof(r)); int a=fork(); if(a==0) { printf("nt PROCESS 2:it splits the given stringn"); read(p1[0],r,sizeof(r)); int n=strlen(r); for(i=0;i<n/2;i++) { s[i]=r[i]; } for(i=n/2;i<=n;i++) { t[j++]=r[i]; } pipe(p3); pipe(p4); write(p3[1],s,sizeof(s)); write(p4[1],t,sizeof(t)); int b=fork(); if(b==0) { printf("p4 %dt",getpid()); printf("p2 %dn",getppid()); read(p3[0],s,sizeof(s)); printf("t PROCESS 4:sub string t %s t",s); printf("no of char=%d n",strlen(s)); }
  • 2. else { int c=fork(); if(c==0) { printf("p5 %dt",getpid()); printf("p2 %dn",getppid()); read(p4[0],t,sizeof(t)); printf("t PROCESS 5:sub string t %s t",t); printf("no of char=%d n",strlen(t)); } else { wait(); printf("p2 %dt",getpid()); printf("p1 %dn",getppid()); } }} else { wait(); int d=fork(); if(d==0) { printf("p3 %dt",getpid()); printf("p1 %dn",getppid()); read(p2[0],r,sizeof(r)); for(i=strlen(r)-1;i>=0;i--) { u[l++]=r[i]; } for(i=0;i<strlen(r);i++) { if(u[i]==r[i]) k++; else continue; } if(k==strlen(r)) printf("t PROCESS 3: the given string is palindromen"); else printf("t PROCESS 3: the given string is not palindromen"); } else { printf("p1 %dt",getpid()); printf("kernal %dtn",getppid());
  • 3. } } } To write aprogram to implement the FCFS scheduling algorithm #include<stdio.h> main() { int n,a[10],b[10],t[10],w[10],g[10],i,m; float att=0,awt=0; for(i=0;i<10;i++) { a[i]=0; b[i]=0; w[i]=0; g[i]=0; } printf("enter the number of process"); scanf("%d",&n); printf("enter the burst times"); for(i=0;i<n;i++) scanf("%d",&b[i]); printf("nenter the arrival times"); for(i=0;i<n;i++) scanf("%d",&a[i]); g[0]=0; for(i=0;i<10;i++) g[i+1]=g[i]+b[i]; for(i=0;i<n;i++) { w[i]=g[i]-a[i]; t[i]=g[i+1]-a[i]; awt=awt+w[i];
  • 4. att=att+t[i]; } awt =awt/n; att=att/n; printf("ntprocesstwaiting timetturn arround timen"); for(i=0;i<n;i++) { printf("tp%dtt%dtt%dn",i,w[i],t[i]); } printf("the average waiting time is %fn",awt); printf("the average turn around time is %fn",att); } c program for round robinnon preemptive cpuscheduling algorithm #include<stdio.h> void main() { int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp; float avg_wt,avg_tat; printf("Enter number of process:"); scanf("%d",&n); printf("nEnter Burst Time:n"); for(i=0;i<n;i++) { printf("p%d:",i+1); scanf("%d",&bt[i]); p[i]=i+1; //contains process number } //sorting burst time in ascending order using selection sort for(i=0;i<n;i++) {
  • 5. pos=i; for(j=i+1;j<n;j++) { if(bt[j]<bt[pos]) pos=j; } temp=bt[i]; bt[i]=bt[pos]; bt[pos]=temp; temp=p[i]; p[i]=p[pos]; p[pos]=temp; } wt[0]=0; //waiting time for first process will be zero //calculate waiting time for(i=1;i<n;i++) { wt[i]=0; for(j=0;j<i;j++) wt[i]+=bt[j]; total+=wt[i]; } avg_wt=(float)total/n; //average waiting time total=0; printf("nProcesst Burst Time tWaiting TimetTurnaround Time"); for(i=0;i<n;i++) { tat[i]=bt[i]+wt[i]; //calculate turnaround time total+=tat[i]; printf("np%dtt %dtt %dttt%d",p[i],bt[i],wt[i],tat[i]); } avg_tat=(float)total/n; //average turnaround time printf("nnAverage Waiting Time=%f",avg_wt); printf("nAverage Turnaround Time=%fn",avg_tat); }
  • 6. write a c program to implement FIFO page replacement algorithm #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 stringt page framesn"); for(i=1;i<=n;i++) { printf("%dtt",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("%dt",frame[k]); } printf("n"); } printf("Page Fault Is %d",count); return 0; }
  • 7. To write ac program to implement LRUpage replacement algorithm #include<stdio.h> main() { int q[20],p[50],c=0,c1,d,f,i,j,k=0,n,r,t,b[20],c2[20]; printf("Enter no of pages:"); scanf("%d",&n); printf("Enter the reference string:"); for(i=0;i<n;i++) scanf("%d",&p[i]); printf("Enter no of frames:"); scanf("%d",&f); q[k]=p[k]; printf("nt%dn",q[k]); c++; k++; for(i=1;i<n;i++) { c1=0; for(j=0;j<f;j++) { if(p[i]!=q[j]) c1++; } if(c1==f) { c++; if(k<f) { q[k]=p[i]; k++; for(j=0;j<k;j++) printf("t%d",q[j]); printf("n"); } else { for(r=0;r<f;r++) { c2[r]=0; for(j=i-1;j<n;j--) { if(q[r]!=p[j])