document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*--------------------------------------------------------------------------------
  2.  Title: Write a program to implement Priority (Non-Preemptive) [Without arrival time] scheduling algorithm.
  3. ---------------------------------------------------------------------------------*/
  4.  
  5. #include<stdio.h>
  6. #include<string.h>
  7.  
  8. int n;
  9.  
  10. struct process
  11. {
  12.     int arr[30];
  13.     char prc[30];
  14.     int at,bt,pt;
  15.     int flags,l,id;
  16.     }p[30];
  17.  
  18. struct tprocess
  19. {
  20.     char prc[30];
  21.     int at,bt;
  22.     }tp1[30];
  23.  
  24. void main()
  25. {
  26.     int wt[10],tat[10];
  27.     int i,j,temp,temp_b,aa[10];
  28.     float awt,sum=0,sum_t=0;
  29.     float th_put,att,tot;
  30.  
  31.     printf("\\n Priority (Non-Preempitve) \\n");
  32.     printf("\\n Enter Number of Process : ");
  33.     scanf("%d",&n);
  34.  
  35.     for(i=0; i<n; i++)
  36.     {
  37.         printf("\\n Enter Process Name : ");
  38.         scanf("%s",p[i].prc);
  39.  
  40.         printf("\\n Enter Burst Time : ");
  41.         scanf("%d",&p[i].bt);
  42.  
  43.         printf("\\n Enter Priority : ");
  44.         scanf("%d",&p[i].pt);
  45.         }
  46.  
  47.     printf("\\n Process Name \\t Burst Time \\t Priority \\n");
  48.     for(i=0; i<n; i++)
  49.     {
  50.         printf("\\n %s \\t\\t %d \\t\\t %d ",p[i].prc,p[i].bt,p[i].pt);
  51.         }
  52.  
  53.     for(i=0; i<n-1; i++)
  54.     {
  55.         for(j=i+1; j<n; j++)
  56.         {
  57.             if(p[i].pt>p[j].pt)
  58.             {
  59.                 temp = p[i].pt;
  60.                 p[i].pt = p[j].pt;
  61.                 p[j].pt = temp;
  62.  
  63.                 temp_b = p[i].bt;
  64.                 p[i].bt = p[j].bt;
  65.                 p[j].bt = temp_b;
  66.                 }
  67.             }
  68.         }
  69.  
  70.     printf("\\n\\n Gaunt Chart : ");
  71.     printf(" 0 ");
  72.     tot=0;
  73.  
  74.     for(i=0;i<n;i++)
  75.     {
  76.         tot = tot+p[i].bt;
  77.         printf(" %s-->%.2f ",p[i].prc,tot);
  78.         tat[i]=tot;
  79.         }
  80.  
  81.     th_put=n/tot;  // calculate throughput : dividing total no. of process by last execution time
  82.     printf("\\n\\n Throughput : %f ",th_put);
  83.  
  84.     for(i=0; i<10; i++)
  85.     {
  86.         wt[i]=0;
  87.         aa[i]=0;
  88.         }
  89.  
  90.     for(i=0; i<n-1; i++)
  91.     {
  92.         wt[i]=wt[i]+tat[i];
  93.         sum=sum+wt[i];
  94.         }
  95.  
  96.     awt=sum/n;
  97.     printf("\\n\\n Wating Time : %f ",sum);
  98.     printf("\\n Average Waiting Time : %f",awt);
  99.  
  100.     for(i=0; i<n; i++)
  101.     {
  102.         aa[i] = aa[i]+tat[i];
  103.         sum_t = sum_t + aa[i];
  104.         }
  105.  
  106.     att=sum_t/n;
  107.     printf("\\n\\n Turn around Time : %f ",sum_t);
  108.     printf("\\n Average Turn around Time : %f",att);
  109.     }
  110.  
  111. //end of the program
  112.  
  113. /*
  114. //------------------
  115. //  OUTPUT
  116. //------------------
  117.  
  118. gescoe@gescoe-Vostro-230:~/Desktop/TE$ gcc a6_PRIO_NonP_WO_AT.c
  119.  
  120. gescoe@gescoe-Vostro-230:~/Desktop/TE$ ./a.out
  121.  
  122.  Priority (Non-Preempitve)
  123.  
  124.  Enter Number of Process : 4
  125.  
  126.  Enter Process Name : p1
  127.  
  128.  Enter Burst Time : 8
  129.  
  130.  Enter Priority : 2
  131.  
  132.  Enter Process Name : p2
  133.  
  134.  Enter Burst Time : 5
  135.  
  136.  Enter Priority : 3
  137.  
  138.  Enter Process Name : p3
  139.  
  140.  Enter Burst Time : 2
  141.  
  142.  Enter Priority : 4
  143.  
  144.  Enter Process Name : p4
  145.  
  146.  Enter Burst Time : 7
  147.  
  148.  Enter Priority : 1
  149.  
  150.  
  151.  
  152.  
  153. Process Name    Burst Time      Priority
  154.  
  155. p1              8               2
  156. p2              5               3
  157. p3              2               4
  158. p4              7               1
  159.  
  160. Gaunt Chart :  0  p1-->7  p2-->15  p3-->20  p4-->22
  161.  
  162. Throughput : 0.181818
  163.  
  164. Waiting Time : 42.000000
  165. Average Waiting Time : 10.500000
  166.  
  167. Turn around Time : 64.000000
  168. Average Turn around Time : 16.000000
  169.  
  170. // EXIT
  171. */
');