# Question 3

Apr 9th, 2019
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Ques. 3. Consider a scheduler which schedules the job by considering the arrival time of the processes where arrival time if given as 0 is discarded or displayed as error. The scheduler implements the shortest job first scheduling policy, but checks the queue of the processes after the every process terminates and time taken for checking and arranging the process according to the shortest job is 2 time unit. Compute the waiting time, turnaround time and average waiting time and turnaround time of the processes. Also compute the total time taken by the processor to compute all the jobs.
2. The inputs for the number of requirements, arrival time and burst time should be provided by the user.
3. Consider the following units for reference.
4. Process Arrival time Burst Time
5. 1 0 6
6. 2 3 2
7. 3 5 1
8. 4 9 7
9. 5 10 5
10. 6 12 3
11. 7 14 4
12. 8 16 5
13. 9 17 7
14. 10 19 2
15. Develop a scheduler which submits the processes to the processor in the defined scenario, and compute the scheduler performance by providing the waiting time for process, turnaround time for process and average waiting time and turnaround time.
16.
17. #include<stdio.h>
18. #include<conio.h>
19. int main()
20. {
21.     int bt[10],p[10],n,temp,i,j,wt[10],sum=0;
22.     float avg;
23.     printf("Enter total no of proces:");
24.     scanf("%d",&n);
25.     printf("\n Enter burst time for each process:-");
26.     for(i=0;i<n;i++)
27.     {
28.         printf("\nBurst time of process P%d:",i);
29.         scanf("%d",&bt[i]);
30.         p[i]=i;
31.     }
32.     for(i=0;i<n-1;i++)
33.     {
34.         for(j=i+1;j<n;j++)
35.         {
36.             if(bt[i]>bt[j])
37.             {
38.                 temp=bt[i];
39.                 bt[i]=bt[j];
40.                 bt[j]=temp;
41.                 temp=p[i];
42.                 p[i]=p[j];
43.                 p[j]=temp;
44.             }
45.         }
46.     }
47.     wt[0]=0;
48.     for(i=1;i<n;i++)
49.     {
50.         wt[i]=wt[i-1]+bt[i-1];
51.     }
52.     for(i=0;i<n;i++)
53.     {
54.         sum+=wt[i];
55.     }
56.     avg=(float)sum/n;
57.     printf("\n Waiting time for each process:-");
58.     for(i=0;i<n;i++)
59.     {
60.         printf("\n Waiting time for process P%d is %d sec.",p[i],wt[i]);
61.
62.     }
63.     printf("\n Average waiting time is %f sec.",avg);
64.     getch();
65.     return 0;
66. }