 question15

Apr 9th, 2019
589
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. Ques. 5. CPU schedules N processes which arrive at different time intervals and each process is allocated the CPU for a specific user input time unit, processes are scheduled using a preemptive round robin scheduling algorithm. Each process must be assigned a numerical priority, with a higher number indicating a higher relative priority. In addition to the processes one task has priority 0. The length of a time quantum is T units, where T is the custom time considered as time quantum for processing. If a process is preempted by a higher-priority process, the preempted process is placed at the end of the queue. Design a scheduler so that the task with priority 0 does not starve for resources and gets the CPU at some time unit to execute. Also compute waiting time, turn around.
3.
4.
5. #include<stdio.h>
6. #include<conio.h>
7. void main()
8. {
9.   char p,temp;
10.   int i,j,pt,wt,totwt=0,pr,temp1,n;
11.   float avgwt;
12.  printf("enter no of processes:");
13.  scanf("%d",&n);
14.   for(i=0;i<n;i++)
15.   {
16.   printf("enter process%d name:",i+1);
17.  scanf("%s",&p[i]);
18.   printf("enter process time:");
19.  scanf("%d",&pt[i]);
20.   printf("enter priority:");
21.   scanf("%d",&pr[i]);
22.   }
23.  for(i=0;i<n-1;i++)
24.  {
25.  for(j=i+1;j<n;j++)
26.  {
27.    if(pr[i]>pr[j])
28.  {
29.    temp1=pr[i];
30.  pr[i]=pr[j];
31.   pr[j]=temp1;
32.   temp1=pt[i];
33.   pt[i]=pt[j];
34.   pt[j]=temp1;
35.  strcpy(temp,p[i]);
36.  strcpy(p[i],p[j]);
37.   strcpy(p[j],temp);
38.   }
39.   }
40.   }
41.  wt=0;
42.   for(i=1;i<n;i++)
43.   {
44.    wt[i]=wt[i-1]+et[i-1];
45.    totwt=totwt+wt[i];
46.    }
47. avgwt=(float)totwt/n;
48. printf("p_name\t p_time\t priority\t w_time\n");
49. for(i=0;i<n;i++)
50. {
51.    printf(" %s\t %d\t %d\t %d\n" ,p[i],pt[i],pr[i],wt[i]);
52.    }
53.   printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
54.   getch();
55.    }
56.
57.
58.
59. OUTPUT:
60. enter no of processes: 5
61. enter process1 name: aaa
62. enter process time: 4
63. enter priority:5
64. enter process2 name: bbb
65. enter process time: 3
66. enter priority:4
67. enter process3 name: ccc
68. enter process time: 2
69. enter priority:3
70. enter process4 name: ddd
71. enter process time: 5
72. enter priority:2
73. enter process5 name: eee
74. enter process time: 1
75. enter priority:1
76. p_name P_time priority w_time
77. eee 1 1 0
78. ddd 5 2 1
79. ccc 2 3 6
80. bbb 3 4 8
81. aaa 4 5 11
82. total waiting time=26
83. avg waiting time=5.20
84. 1
85. 2
86. 3
87. 4
88. 5
89. 6
90. 7
91. 8
92. 9
93. 10
94. 11
95. 12
96. 13
97. 14
98. 15
99. 16
100. 17
101. 18
102. 19
103. 20
104. 21
105. 22
106. 23
107. 24
108. 25
109. 26
110. 27
111. 28
112. 29
113. 30
114. 31
115. 32
116. 33
117. 34
118. 35
119. 36
120. 37
121. 38
122. 39
123. 40
124. 41
125. 42
126. 43
127. 44
128. 45
129. 46
130. 47
131. 48
132. 49
133. 50
134. 51
135. 52
RAW Paste Data