Thursday, August 27, 2009

Job scheduling



#include<stdio.h>



#include<conio.h>




int

pd[10],pd1[10],pd2[10];




void

main()



{



int c=50,ch,i,j,k,l,m=0,max=0,n,p[10],pp[10],pr,t,tq,ti;



int pt[10],pri[10];



int a[10];



void line(int);



void space(int);



clrscr();



printf("\n\n\t\tJob
Scheduling"
);



printf("\n\t\t~~~
~~~~~~~~~~"
);



do



{



printf("\n
Enter the number of Process(n>2):"
);



scanf("%d",&n);



}while(n<2);



for(i=1;i<=n;i++)



{



printf("\nEnter
the CPU Burst Time of process %d:"
,i);



scanf("%d",&pd[i]);



a[i]=i;



}



do



{



printf("\n\nSelect
the Scheduling Choice:"
);



printf("\n\t1.First
Come First Service(FCFS)"
);



printf("\n\t2.Shortest
Job First(SJF)"
);



printf("\n\t3.Priority\n\t4.Round
Robin"
);



printf("\n\t5.Exit\n\tEnter
Your Choice:"
);



scanf("%d",&ch);



switch(ch)



{



case
1:



printf("\n\n\t\tFirst
Come First Service(FCFS)"
);



printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");



m = 0;



line(c);



for(i=1;i<=n;i++)



{




printf("P%d",i);




space(pd[i]);



}



printf("");



line(c);



for(i=1;i<=n;i++)



{




printf("%d",m);




m = m + pd[i];




space(pd[i]+2);



}



printf("%d",m);



break;



case
2:



printf("\n\n\t\tShortest
Job First(SJF)"
);



printf("\n\t\t~~~~~~~~~~~~~~~~~~~~~~~");



for(i=1;i<=n;i++)




pd1[i] = pd[i];




for
(i=1;i<=n;i++)




for(j=1;j<=n;j++)




{




if(pd1[i]<pd1[j])




{




t = pd1[i]; pd1[i] = pd1[j]; pd1[j] = t;




t=a[i]; a[i]=a[j]; a[j]=t;




}









}




line(c);



for(i=1;i<=n;i++)



{




printf("P%d",a[i]);




space(pd1[i]);



}



printf("");



line(c);



m=0;



for(i=1;i<=n;i++)



{




printf("%d",m);




m = m + pd1[i];




space(pd1[i]+2);



}



printf("%d",m);



break;



case
3:



printf("\n\n\t\tPriority\n\t\t~~~~~~~~~");



for(i=1;i<=n;i++)



{




AB:




printf("\nEnter the Priority of process P%d:",i);




scanf("%d",&p[i]);




for(j=1;j<i;j++)




if((p[j]==p[i])(p[i]>n))




{




printf("\n\t!process P%d priority
is already exist OR >n"
,i);




goto AB;




}




pt[p[i]]=pd[i];




pri[p[i]]=i;



}



line(c);



for(i=1;i<=n;i++)



{




printf("P%d",pri[i]);




space(pt[i]);



}



printf("");



line(c);



m=0;



for(i=1;i<=n;i++)



{




printf("%d",m);




m = m + pt[i];




space(pt[i]+2);



}



printf("%d",m);



break;



case
4:



printf("\n\n\t\tRound
Robin\n\t\t~~~~~~~~~~~~"
);



printf("\nEnter
the CPU Execution Time of each Process:"
);



scanf("%d",&ti);




for(j=1;j<=n;j++)




if(max<pd[j])




max = pd[j];



max = max / 2;



for(i=1;i<=n;i++)




pd2[i]=pd[i];



line(c);



m=k=0;



for(i=1;i<=max;i++)




for(j=1;j<=n;j++)




{




if(pd2[j]>0)




{




if(pd2[j]>=ti)




{




printf("P%d",j);




space(ti);




pd2[j]=pd2[j]-ti;




k++;




pd1[k]=ti;




}




else if(pd2[j]<ti)




{




printf("P%d",j);




space(ti-1);




k++;




pd1[k]=pd2[j];



pd2[j]=0;




}




}




}



printf("");



line(c);



for(i=1;i<=k;i++)



{




printf("%d",m);




space(ti+2);




m = m +pd1[i];



}



break;



}



}while(ch<=4);



}




void

line(int c)



{



int i;



printf("\n\t");



for(i=1;i<=c;i++)



printf("-");



printf("\n\t");



}




void

space(int c)



{



int i;



for(i=1;i<=c;i++)



printf(" ");



}


Click to Download Source Code
or
Copy and past in browser address bar

http://sites.google.com/site/senthilmcan/software-programs


No comments:

Post a Comment