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).
Related
I have searched the internet for examples for the algorithms in cpu scheduling and I have never seen any examples with the same arrival time.
Is it possible to make the processes have the same arrival time?
For example:
Algorithm: Round Robin
Process ---- Arrival Time ----- Burst Time
P1 ----------------- 3 ------------------ 4 -----
P2 ----------------- 1 ------------------ 5 -----
P3 ----------------- 1 ------------------ 3 -----
Quantum = 1
What would be the gantt chart look like?
Is it possible to make the processes have the same arrival time?
Yes, for normal definitions of "same time" (e.g. excluding "in the same Planck time quantum") it's possible for processes to have the same arrival time.
For an example, imagine if 100 tasks sleep until midnight. When midnight occurs a timer IRQ handler processes a list of tasks waiting to wake up and wakes up 100 tasks at the "same" time.
Now, for this example you could say that "same time" is stricter; and that the timer IRQ handler processes the list of tasks sequentially and adds them to scheduler's queues sequentially, and that it's only "almost at the same time". In this case it's still possible to have N CPUs running in parallel (with a different timer for each CPU) that happen to wake (up to) N tasks at the same time.
Of Course, multiple processes can have the same arrival time i.e the time they came for looking the CPU to execute them. And its the responsibility of the Processor to handle and schedule them accordingly as per the appropriate Scheduling Algorithms.
When the Arrival time for two or more processes are same, then the RR-Scheduling follows FCFS {First come first serve} approach. Here in Round robin scheduling with quantum = 1, we have
Gantt Chart
At time 0, no process
At time 1 , we have P2 and P3 with P2 first then after a quantum RR executes P3,
At time 3 we have all three processes with order P2,P3,P1 hence the RR-Algorithm will keep switching between them until they complete their execution (burst) time.
And we will get all executed at time 13.
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.
In operating systems of supercomputers, which handles a big quantity of tasks at the same time, is there any situation when SJF policy is taking longer than FCFS policy, speaking of waiting time metric?
It can be assumed that more than one core are present in the system.
First I thought that it is not possible, then I took some time and finally arrived at this result:
Yes it can be.
Suppose that ready queue is filled with processes with equal burst times(all = x):
Process Burst time
P1 x
P2 x
P3 x
P4 x
. .
. .
. .
Pn x
Now in this case what FCFS would do, the process that would come first will be allocated the CPU and then the next process which comes first will be allocated the CPU and so on without wasting any time.
But what SJF will do is :it will first find the job with the shortest burst time from the available jobs in the ready queue which in this case is wastage of time as all have equal burst times and SJF would end up traversing the ready queue without any fruitful result.
Can any one guide how to implement Process Aging?
I would Like to know on what factors does this Aging factor depend on?
According to me, it should depend on present priority and average waiting time.
How do I implement averaging waiting time?
Can any one please give clear idea on it?
The process aging should depend only on the waiting time (according to the original concept) of the process. Based on its original idea, the priority of a process will be increased accordingly to the time it is waiting in the ready queue.
read the process arrival time, burst time, process id, priority from the text file and calculate the average waiting time and show the cpu utilization of each cycle like this,
Time 1 P3 arrives
Time 1 P3 runs
Time 2 P5 arrives
Time 2 P3 runs
Time 10 P1 arrives
Time 10 P3 runs
Time 13 P3 finishes
Time 13 P5 runs
Time 16 P4 arrives
Time 16 P5 runs
Time 53 P5 finishes
Time 53 P1 runs
Time 82 P1 finishes
Time 82 P4 runs
Time 112 P4 finishes
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!