Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*--------------------------------------------------------------------------------
- Title: Write a program to implement Priority (Non-Preemptive) [Without arrival time] scheduling algorithm.
- ---------------------------------------------------------------------------------*/
- #include<stdio.h>
- #include<string.h>
- int n;
- struct process
- {
- int arr[30];
- char prc[30];
- int at,bt,pt;
- int flags,l,id;
- }p[30];
- struct tprocess
- {
- char prc[30];
- int at,bt;
- }tp1[30];
- void main()
- {
- int wt[10],tat[10];
- int i,j,temp,temp_b,aa[10];
- float awt,sum=0,sum_t=0;
- float th_put,att,tot;
- printf("\n Priority (Non-Preempitve) \n");
- printf("\n Enter Number of Process : ");
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- printf("\n Enter Process Name : ");
- scanf("%s",p[i].prc);
- printf("\n Enter Burst Time : ");
- scanf("%d",&p[i].bt);
- printf("\n Enter Priority : ");
- scanf("%d",&p[i].pt);
- }
- printf("\n Process Name \t Burst Time \t Priority \n");
- for(i=0; i<n; i++)
- {
- printf("\n %s \t\t %d \t\t %d ",p[i].prc,p[i].bt,p[i].pt);
- }
- for(i=0; i<n-1; i++)
- {
- for(j=i+1; j<n; j++)
- {
- if(p[i].pt>p[j].pt)
- {
- temp = p[i].pt;
- p[i].pt = p[j].pt;
- p[j].pt = temp;
- temp_b = p[i].bt;
- p[i].bt = p[j].bt;
- p[j].bt = temp_b;
- }
- }
- }
- printf("\n\n Gaunt Chart : ");
- printf(" 0 ");
- tot=0;
- for(i=0;i<n;i++)
- {
- tot = tot+p[i].bt;
- printf(" %s-->%.2f ",p[i].prc,tot);
- tat[i]=tot;
- }
- th_put=n/tot; // calculate throughput : dividing total no. of process by last execution time
- printf("\n\n Throughput : %f ",th_put);
- for(i=0; i<10; i++)
- {
- wt[i]=0;
- aa[i]=0;
- }
- for(i=0; i<n-1; i++)
- {
- wt[i]=wt[i]+tat[i];
- sum=sum+wt[i];
- }
- awt=sum/n;
- printf("\n\n Wating Time : %f ",sum);
- printf("\n Average Waiting Time : %f",awt);
- for(i=0; i<n; i++)
- {
- aa[i] = aa[i]+tat[i];
- sum_t = sum_t + aa[i];
- }
- att=sum_t/n;
- printf("\n\n Turn around Time : %f ",sum_t);
- printf("\n Average Turn around Time : %f",att);
- }
- //end of the program
- /*
- //------------------
- // OUTPUT
- //------------------
- gescoe@gescoe-Vostro-230:~/Desktop/TE$ gcc a6_PRIO_NonP_WO_AT.c
- gescoe@gescoe-Vostro-230:~/Desktop/TE$ ./a.out
- Priority (Non-Preempitve)
- Enter Number of Process : 4
- Enter Process Name : p1
- Enter Burst Time : 8
- Enter Priority : 2
- Enter Process Name : p2
- Enter Burst Time : 5
- Enter Priority : 3
- Enter Process Name : p3
- Enter Burst Time : 2
- Enter Priority : 4
- Enter Process Name : p4
- Enter Burst Time : 7
- Enter Priority : 1
- Process Name Burst Time Priority
- p1 8 2
- p2 5 3
- p3 2 4
- p4 7 1
- Gaunt Chart : 0 p1-->7 p2-->15 p3-->20 p4-->22
- Throughput : 0.181818
- Waiting Time : 42.000000
- Average Waiting Time : 10.500000
- Turn around Time : 64.000000
- Average Turn around Time : 16.000000
- // EXIT
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement