Esd

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

1)IMPLEMENTATION OF ROUND ROBIN SCHEDULING ALGORITHM AIM To write a c program to implement the round robin scheduling algorithm ALGORITHM

1. Start the process 2. Declare the array size 3. Get the number of elements to be inserted 4. Get the value 5. Set the time sharing system with preemption 6. Define quantum is defined from 10 to 100ms 7. Declare the queue as a circular 8. Make the CPU scheduler goes around the ready queue allocating CPU to each pro cess for the time interval specified 9. Make the CPU scheduler picks the first process and sets time to interrupt aft er quantum expired dispatches the process 9. If the process have burst less than the time quantum than the process release the CPU 10. If the process have bust greater then time quantum then time will go off and cause interrupt to OS and the process put into the tail of ready queue and the s chedule select next process 11. Display the results 12. Stop the process PROGRAM: #include<stdio.h> int ttime,i,j,temp; main() { int pname[10],btime[10],pname2[10],btime2[10]; int n,x,z; printf("Enter the no. of process:"); scanf("%d",&n); printf("Enter the process name and burst time for the process\n"); for(i=0;i<n;i++) { printf("Enter the process name:"); scanf("%d",&pname2[i]); printf("Enter burst time for the process %d:",pname2[i]); scanf("%d",&btime2[i]); }

printf("PROCESS NAME \t\t BURST TIME\n"); for(i=0;i<n;i++) printf("%d\t\t\t %d\n",pname2[i],btime2[i]); z=1; while(z==1) { ttime=0; for(i=0;i<n;i++) { pname[i]=pname2[i]; btime[i]=btime2[i]; } printf ("PRESS 1.ROUND ROBIN 2.EXIT\n"); scanf("%d",&x); switch(x) { case 1: rrobin(pname,btime,n); break; case 2: exit(0); break; default: printf("Invalid option"); break; } printf("\n\n If you want to continue press 1:"); scanf("%d",&z); } } rrobin(int pname[],int btime[],int n) { int tslice; j=0; printf("\n\t ROUND ROBIN SCHEDULING \n\n"); printf("Enter the time slice:\n"); scanf("%d",&tslice); printf("PROCESS NAME \t REMAINING TIME\t TOTAL TIME"); while(j<n) { for(i=0;i<n;i++) { if(btime[i]>0) { if(btime[i]>=tslice) { ttime+=tslice; btime[i]=btime[i]-tslice; printf("\n%d\t\t %d \t\t %d",pna me[i],btime[i],ttime); if(btime[i]==0) j++; } else { ttime+=btime[i];

btime[i]=0; printf("\n%d\t\t %d \t\t %d",pna me[i],btime[i],ttime); } } } } } OUTPUT: Enter the no. of process: 4 Enter the process name and burst Enteer the process name: 1 Enter burst time for the process Enteer the process name: 2 Enter burst time for the process Enteer the process name: 3 Enter burst time for the process Enteer the process name: 4 Enter burst time for the process PROCESS NAME 1 2 3 4 PRESS 1.ROUND ROBIN 2.EXIT 1 ROUND ROBIN SCHEDULING Enter the time slice: 2 PROCESS NAME REMAINING TIME TOTAL TIME 1 6 2 2 1 4 3 4 6 4 0 7 1 4 9 2 0 10 3 2 12 1 2 14 3 0 16 --------------------------------------------------------------------------------------------------#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> void main() { char p[10][5]; int et[10],wt[10],timer=3,count,pt[10],rt,i,j,totwt=0,t,n=5,found=0,m; float avgwt; clrscr(); for(i=0;i<n;i++) { time for the process 1: 8 2: 3 3: 6 4: 1 8 3 6 1

BURST TIME

printf("enter the process name : "); scanf("%s",&p[i]); printf("enter the processing time : "); scanf("%d",&pt[i]); } m=n; wt[0]=0; i=0; do { if(pt[i]>timer) { rt=pt[i]-timer; strcpy(p[n],p[i]); pt[n]=rt; et[i]=timer; n++; } else { et[i]=pt[i]; } i++; wt[i]=wt[i-1]+et[i-1]; }while(i<n); 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); } -----------------------------------------------------------------------------------------------

2)C Program for Shortest Job First Scheduling Algorithm #include<stdio.h> #include<conio.h> #include<dos.h> void main() { int n,b[10],w[10],i,j,h,t,tt; int stime[10],a[10]; float avg=0; clrscr(); printf("\n\tJOB SCHEDULING ALGORITHM[SJF]"); printf("\n\t*****************************************************\n"); printf("\nEnter howmany jobs:"); scanf("%d",&n); printf("\nEnter burst time for corresponding job....\n"); for(i=1;i<=n;i++) { printf("\nProcess %d:",i); scanf("%d",&b[i]); a[i]=i; } for(i=1;i<=n;i++) for(j=i;j<=n;j++) if(b[i]>b[j]) { t=b[i]; tt=a[i]; b[i]=b[j]; a[i]=a[j]; b[j]=t; a[j]=tt; } w[1]=0; printf("\nprocess %d waiting time is 0",a[1]); for(i=2;i<=n;i++) { w[i]=b[i-1]+w[i-1]; printf("\nProcess %d waiting time: %d",a[i],w[i]); avg+=w[i]; } printf("\ntotal waiting time:%f",avg); printf("\n\nthe average waiting time is:%f\n",avg/n); printf("\nGaunt Chart\n***************************************\n\n\t"); h=22; for(i=1;i<=n;i++) { printf("%d",b[i]); for(j=1;j<=b[i];j++) printf("%c",h); } printf("\n\t"); for(i=1;i<=n;i++) {

printf("%d",w[i]); for(j=1;j<=w[i];j++) printf("%c",h); delay(1000); } getch(); }

SAMPLE INPUT AND OUTPUT: Enter howmany jobs:3 Enter burst time for corresponding job.... Process 1:5 Process 2:2 Process 3:3 process 2 waiting time is 0 Process 3 waiting time: 2 Process 1 waiting time: 5 total waiting time:7.000000 the average waiting time is:2.333333 ---------------------------------------------------------------------------------------------------------------

You might also like