Shortest Job First Scheduling - operating-system

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!

Related

Shortest Process Next Scheduling Algorithm

I am wondering which answer is correct?For answer 1, when P5 is finish executing, then we compared about P3,P6 and P4 ,if we compare them according to the arrival time then P3 will execute first. So,my question is about do we need to follow the arrival time? Which answer is correct? Thanks.
This is the question image
The first answer is correct.
A case could be made that both are correct, but the first is "more correct." The tiebreaker for this scheduling algorithm should be the arrival time. Your goal is to minimize the process wait time, and it makes more sense to first run the process that has been waiting longer.
Algorithms like this will often use a priority queue, which would sort the elements from shortest burst time to longest burst time. Queues use FIFO (first in, first out), which means if there are two elements with the same burst time, the one that was added first would be selected first.

Shortest job first job with preemption allowed Anamoly

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.

Shortest Remaining Time First Query

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).

How does operating system knows execution time of process

I was revisiting Operating Systems CPU job scheduling and suddenly a question popped in my mind, How the hell the OS knows the execution time of process before its execution, I mean in the scheduling algorithms like SJF(shortest job first), how the execution time of process is calculated apriori ?
From Wikipedia:
Another disadvantage of using shortest job next is that the total execution time of a job must be known before execution. While it is not possible to perfectly predict execution time, several methods can be used to estimate the execution time for a job, such as a weighted average of previous execution times.[1]
More on http://en.wikipedia.org/wiki/Shortest_job_next
Also, O.S can compute the total needed time for each task, by means of first calculating its CPI.
(CPI: cycles per instruction)
There is a weighted average CPI for each job.
For example, floating point instructions weigh much more than fixed point instructions, meaning they take more time to perform. So a job dealing with fixed point operations: like add or increment is perceived to be shorter. Hence in a shortest job first, it shall be executed prior to the aforementioned job.

Round Robin Scheduling : Two different solutions - How is that possible?

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.