Consider the following scenario, and take this as preemptive Shortest first job executing algorithm.
[1]
The problem here is at the timeline (3), p2 has 1 burst time available, but p4 which is now available has 2 burst time, so my question is why is p2 is not continuing the execution, and why p4 is starting?, Is this diagram wrong or have i misunderstood in any way.
Gantt chart has to be like:
Average waiting time should be [(0+11) + 0 + 4 + 9] /4 =6.
Related
so far I know that in SJF the execution is done first which BT is low based on the AT.
but if there also attach Priority, how do reach the solution
Process Arrival Time Burst Time Priority
P1 7 3 2
P2 5 2 4
P3 4 5 1
P4 0 4 3
I'm doing a Real Time Systems course, and we in the class are stuck in some assumptions in the section 4 of the paper of Liu and Layland about Rate-Monotonic Scheduling that we can not fully understand:
If floor(T2/T1) is the number of Times that Task1 interferes in Task2 why the function applied to T2/T1 is floor and not ceil?
Also, there are these equations:
According to the paper, and as we clearly see in the image, equation (1) is a necessary condition but not sufficient, while equation (2) is a sufficient condition. This gives sense to me, but why do the authors state as a conclusion this:
In other words, whenever the T1 < T2 and C1,C2 are such that the task scheduling is feasible with Task2 at higher priority than Task1, it is also feasible with Task1 at higher priority than Task2 (but opposite is not true)[...] Specifically, tasks with higher request rates will have higher priorities.
If the second equation, where Task2 have the highest priority, is a sufficient condition, why could we assume that the task scheduling would be feasible if Task1 have the highest priority instead of Task2?
I hope i explained myself well, please feel free to tell me also if i've understood wrong the article statements.
EDIT:
As requested, here is a little explanation to the terms in the article and presented in this question.
In the article, T1 refers to the Period (and Deadline) of Task1,
and T2 to the Period (and Deadline) of Task2.
C1 and C2 refer to the runtime of Task1 and Task2 each one.
First of all, too bad you didn't include what T's and C's mean. I had to read the article, but it was an interesting read so thanks.
It's pretty straightforward. The first equation (1) defines what is the highest possible T2 period value - it cannot be longer than C2 (time needed to execute task 2) plus C1 multiplied by the number of times task 1 is requested during period T2 (hence, floor(T1/T2)) AND CAN FULLY EXECUTE. If T1 is requested, it's executed no matter what, as in this case it's the highest priority task. Task 2 is not able to execute if task 1 is currently executing.
Consider the equation (1) with certain values. Let's use the values suggested in the article. T2 = 5, T1 = 2, C1 = C2 = 1. The floor(T2/T1) gives us the number of requests of task 1 that occur during task 2 period. It's 2 (floor(5/2)). If it would be ceiling(T2/T1) than the result would be 3, which is obviously wrong, as the third request was indeed executed (as depicted in Figure 2), but the period didn't end. To understand it better, consider the same case, but extend the task 1 execution time C1 to 1.5. Below is the timeline for such a system, which is feasible. It fulfills the equaiton (1). If we would use ceiling(T2/T1) then the equation would not be fulfilled, and you clearly see below that the system is fine. I think this will help you see and understand the difference - we need to take into account not the number of times the task is requested, but the number of times the full period of a higher priority task can fit in the period of the lower priority task).
Tasks timeline. Image made using Excel. One "column" is 0.5 unit of time
That's the first part of my answer, need to take some more time to answer the other part of your question. I'll post an update soon.
Anyway, thanks for linking to an interesting article.
If they are two processes with the following Data, How should the Gantt Chart be?(SRTF scheduling)
Process Arrival Burst
P1 0 17
P2 1 16
So will the process P1 be completed first and then P2 will start executing..or P1 will have to wait for 16 milli seconds?
I feel the conflict can be resolved either by choosing the process which came earlier or by the process which has the longest burst. In this case, on choosing either of the approaches, P1 will be completed first.
It's going to choose P1 because at the time P2 didn't exist
P1 AT =0 thus will start first
next step they will be equal but as the processor is working already on p1 it will prefer to keep working on it until interruption or termination
In this case it gets P2 at 1, then it checks for remaining time. As both remaining times are same, it put new process; P2 in the queue for next execution(after P1's completion).
Suppose that following processes arrive for the execution at the times indicated. Each process will run the listed amount of time.
Process [Arrival Time(ms) , Burst Time(ms)]
A[0 , 5] , B[3 , 5] , C[5 , 3] , D[7 , 2]
I want to draw Gantt chart and calculate average waiting time for preemptive Shortest Job First Scheduling.
Solution
http://imgur.com/fP8u61C
Waiting Time is 2ms.
Just Please tell me if this is correct.
The step where I have doubt is that at 3ms when process B arrives, will the scheduler complete the process A or start process B.
Yes, your answer is correct. In fact the problem as posed is ambiguous, but both possibilities give the same answer.
First, the ambiguity : Shortest Job First scheduling is not usually considered preemptive. The preemptive variant is called Shortest Remaining Time First Scheduling (see for instance the Shortest Job Next entry on Wikipedia. However, your exercice states "preemptive Job First scheduling", and that's ambiguous...
Second, however, the only time when there might be a difference between these two scheduling policies is, as you mentioned, at t=3 when both A and B are eligible. But if the scheduling is non-preemptive, of course A continues to execute. It it's preemptive, we must consider the remaining time : A has 2 ms left while B has its whole 5... so A still gets the CPU.
Finally, the waiting times are : A -> 0 ms, B -> 7 ms, C -> 0 ms, D -> 1ms, the average of which is indeed 2 ms.
You probably have to do on your own your homework.
Show your try on that and say what are you questions and your issues.
Don't wait for a complete ready solution!
Problem :
Five batch jobs A through E, arrive at a computer center at almost the same time. They have estimated running times 10, 6, 2, 4, and 8 minutes. Their (externally determined) priorities are 3, 5, 2, 1, and 4, respectively, with 5 being the highest priority. Determine the mean process turn around time. Ignore process switching overhead. For Round Robin Scheduling, assume that the system is multiprogramming, and that each job gets it fair share of the CPU.All jobs are completely CPU bound.
Solution #1 The following solution comes from this page :
For round robin, during the first 10 minutes, each job gets 1/5 of the
CPU. At the end of the 10 minutes, C finishes. During the next 8
minutes, each job gets 1/4 of the CPU, after which time D finishes.
Then each of the three remaining jobs get 1/3 of the CPU for 6
minutes, until B finishes and so on. The finishing times for the five
jobs are 10, 18, 24. 28, 30, for an average of 22 minutes.
Solution #2 the following solution comes from Cornell University, can be found here, and is obviously different from the previous one even though the problem is given in exactly the same form (this solution, by the way, makes more sense to me) :
Remember that the turnaround time is the amount of time that elapses
between the job arriving and the job completing. Since we assume that
all jobs arrive at time 0, the turnaround time will simply be the time
that they complete. (a) Round Robin: The table below gives a break
down of which jobs will be processed during each time quantum. A *
indicates that the job completes during that quantum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
A B C D E A B C* D E A B D E A B D* E A B E A B* E A E A E* A A*
The results are different: In the first one C finishes after 10 minutes, for example, whereas in the second one C finishes after 8 minutes.
Which one is the correct one and why? I'm confused.. Thanks in advance!
The problems are different. The first problem does not specify a time quantum, so you have to assume the quantum is very small compared to a minute. The second problem clearly specifies a one minute scheduler quantum.
The mystery with the second solution is why it assumes the tasks run in letter order. I can only assume that this an assumption made throughout the course and so students would be expected to know to make it here.
In fact, there is no such thing as a 'correct' RR algorithm. RR is merely a family of algorithms, based on the common concept of scheduling several tasks in a circular order. Implementations may vary (for example, you may consider task priorities or you may discard them, or you may manually set the priority as a function of task length or whatever else).
So the answer is - both algorithms seem to be correct, they are just different.