disk scheduling and cpu scheduling
TRANSCRIPT
-
8/8/2019 disk scheduling and cpu scheduling
1/10
#include#include
void roundrobin();void prioritypre();void srt();
void fifo();void prioritynonpre();void sjf();
void fcfs();void lru();
int main(){
int choice1,choice2,choice3,choice4,choice5;
// clrscr();
while(1){
//clrscr();printf("Enter your choice : \n1 for CPU Scheduling algorithms \n
2 for Memory Management algorithms \n0 for EXIT \n Enter : ");scanf("%d",&choice1);if(choice1 == 1){//clrscr();printf("Enter your choice : \n1 for Pre-emptive \n2 for Non-Pree
mptive \n0 to GO BACK \n Enter : ");scanf("%d",&choice2);
if(choice2 == 1){//clrscr();printf("Enter your choice : \n1 for Round Robin \n2 for Priorit
y (Pre-emptive)\n3 for SRT \n0 to GO BACK \n Enter : ");scanf("%d",&choice3);if(choice3 == 1)
{roundrobin();}else if(choice3 == 2)
{prioritypre();}else if(choice3 == 3){srt();}else if(choice3 == 0){
break;}else{
printf("\n\n\t INVALID INPUT");printf("\n\t Press any key to continue......");getch();
-
8/8/2019 disk scheduling and cpu scheduling
2/10
}}else if(choice2 == 2){//clrscr();printf("Enter your choice : \n1 for FIFO \n2 for Priority (Non Pre-empt
ive) \n3 for SJF \n0 to GO BACK \n Enter : ");
scanf("%d",&choice4);if(choice4 == 1){
fifo();}else if(choice4 == 2){prioritynonpre();}else if(choice4 == 3){sjf();
}else if(choice4 == 0){break;}else{printf("\n\n\t INVALID INPUT");printf("\n\t Press any key to continue......");getch();}}else if(choice2 == 0)
{break;}else{printf("\n\n\t INVALID INPUT");printf("\n\t Press any key to continue......");getch();}}else if(choice1 == 2){//clrscr();printf("Enter your choice : \n1 for FCFS \n2 for LRU \n0 to GO BACK \n Enter : ");scanf("%d",&choice5);if(choice5 == 1){fcfs();}else if(choice5 == 2){lru();}else if(choice5 == 0)
{break;}
-
8/8/2019 disk scheduling and cpu scheduling
3/10
else{printf("\n\n\t INVALID INPUT");printf("\n\t Press any key to continue......");getch();}}
else if(choice1 == 0){break;}else{printf("\n\n\t INVALID INPUT");printf("\n\t Press any key to continue......");getch();}}getch();
return 0;}
void sjf(){int burst[4],arrival[4],done[4],waiting[4];int i,j,sum,min;int temp;
sum = 0;
printf("\n\n\tEnter the details of the processes ");for(i=0;i
-
8/8/2019 disk scheduling and cpu scheduling
4/10
}temp = i - arrival[j];i = i + burst[j];done[j] = 1;waiting[j] = temp;printf("\ntemp = %d",temp);}
for(i=0;i
-
8/8/2019 disk scheduling and cpu scheduling
5/10
{if(lefttime[j] > 0 && arrival[j] < i ){if(burst[j] < gap){//printf("\nProcessing p%d in less",j);lefttime[j] = 0;
waiting[j] = waiting[j] + (i - last[j]);last[j] = i;//printf(" Waiting = %d",waiting[j]);i = i + lefttime[j];
}else if(burst[j] > gap){//printf("\nProcessing p%d in more",j);lefttime[j] = lefttime[j] - gap;waiting[j] = waiting[j] + (i - last[j]);last[j] = i;
//printf(" Waiting = %d",waiting[j]);i = i + gap;}
}
if(j
-
8/8/2019 disk scheduling and cpu scheduling
6/10
}
printf("\n\nEnter the buffer size : ");scanf("%d",&buf);
for(j=0;j
-
8/8/2019 disk scheduling and cpu scheduling
7/10
for(l=i;l>=0;l++){
for(j=buf-1;j>=0;j--){if(abc[j] == page[l])
{fla = 0;break;}}
if(fla == 1){abc[count] = page[l];count++;}if(count == (buf-1))
{rep = abc[buf-1];break;}}for(l=0;l
-
8/8/2019 disk scheduling and cpu scheduling
8/10
for(i=0;i
-
8/8/2019 disk scheduling and cpu scheduling
9/10
scanf("%d",&page[i]);}
printf("\n\nEnter the buffer size : ");scanf("%d",&buf);for(j=0;j
-
8/8/2019 disk scheduling and cpu scheduling
10/10
{printf(" %d",buff[l]);}}}}
printf("\n\nPage faults = %d",pagefault);printf("\nPage replacements are = %d",pagefault-buf);printf("\n\nPress any key to continue.....");getch();}