csenotes12

Question 6

Apr 9th, 2019
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.53 KB | None | 0 0
  1. Write a program to implement priority scheduling algorithm with context switching time. Prompt to user to enter the number of processes and then enter their priority, burst time and arrival time also. Now whenever operating system preempts a process and shifts cpu’s control to some another process of higher priority assume that it takes 2 seconds for context switching(dispatcher latency).Form a scenario, where we can give the processes are assigned with priority where the lower integer number is higher priority and then context switch .. as the process waits the priority of the process increase at rate of one per 2 time units of wait.
  2. Calculate waiting time and turnaround time for each process.
  3.  
  4. #include<stdio.h>
  5. #include<conio.h>
  6. int main()
  7. {
  8.     int B_T[10],Process_no[10],W_T[10],T_A_T[10];
  9.     int A_T[10],Prior[10],i,j,Number_of_Process,tot=0,flag,temp,Avg_W_T,Avg_T_A_T;
  10.     printf("Enter Number of Process:");
  11.     scanf("%d",&Number_of_Process);
  12.     printf("\nEnter Burst Time and Prior\n");
  13.     for(i=0;i<Number_of_Process;i++)
  14.     {
  15.         printf("\nP[%d]\n",(i+1));
  16.         printf("Enter Burst Time:");
  17.         scanf("%d",&B_T[i]);
  18.         printf("Enter Arrival Time:");
  19.         scanf("%d",&A_T[i]);
  20.         printf("Enter Prior:");
  21.         scanf("%d",&Prior[i]);
  22.         Process_no[i]=i+1;
  23.     }
  24.     for(i=0;i<Number_of_Process;i++)
  25.     {
  26.         flag=i;
  27.         for(j=i+1;j<Number_of_Process;j++)
  28.         {
  29.             if(Prior[j]<Prior[flag])
  30.             flag=j;
  31.         }
  32.         temp=Prior[i];
  33.         Prior[i]=Prior[flag];
  34.         Prior[flag]=temp;
  35.         temp=B_T[i];
  36.         B_T[i]=B_T[flag];
  37.         B_T[flag]=temp;
  38.         temp=Process_no[i];
  39.         Process_no[i]=Process_no[flag];
  40.         Process_no[flag]=temp;
  41.     }
  42.     W_T[0]=0;  
  43.     for(i=1;i<Number_of_Process;i++)
  44.     {
  45.         W_T[i]=0;
  46.         for(j=0;j<i;j++)
  47.             W_T[i]+=B_T[j];
  48.         tot+=W_T[i];
  49.     }
  50.     Avg_W_T=tot/Number_of_Process;  
  51.     tot=0;
  52.     printf("_______________________________________________________________");
  53.     printf("\nProcess\t       B T              W T                T A T");
  54.     for(i=0;i<Number_of_Process;i++)
  55.     {
  56.         T_A_T[i]=B_T[i]+W_T[i];  
  57.         tot+=T_A_T[i];
  58.         printf("\nProcess %d \t %d\t \t   %d\t\t%d",Process_no[i],B_T[i],W_T[i],T_A_T[i]);
  59.     }
  60.         printf("\n_______________________________________________________________");
  61.     Avg_T_A_T=tot/Number_of_Process;
  62.     printf("\n\nAvg W T= %d",Avg_W_T);
  63.     printf("\nAvg T A T= %d",Avg_T_A_T);
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment