23

In SJF (Shortest Job First) Scheduling method.

enter image description here

How to calculate Average Waiting Time and average Turn-around time?

Is Gannt Chart correct ?

enter image description here

Servy
  • 202,030
  • 26
  • 332
  • 449
Failed_Noob
  • 1,347
  • 18
  • 51
  • 67

4 Answers4

25

Gantt chart is wrong... First process P3 has arrived so it will execute first. Since the burst time of P3 is 3sec after the completion of P3, processes P2,P4, and P5 has been arrived. Among P2,P4, and P5 the shortest burst time is 1sec for P2, so P2 will execute next. Then P4 and P5. At last P1 will be executed.

Gantt chart for this ques will be:

| P3 | P2 | P4 | P5 | P1 |

1    4    5    7   11   14

Average waiting time=(0+2+2+3+3)/5=2

Average Turnaround time=(3+3+4+7+6)/5=4.6

vinayawsm
  • 845
  • 9
  • 28
Hifzan
  • 274
  • 3
  • 3
  • 1
    How to caluclate the response time for the same ? – Akhil Nadh PC Dec 06 '16 at 09:49
  • @Pc_ Response time would be the duration between job submission and the start of execution of job. For P3 it would be 0(1 - 1), for P2 its 2(4 - 2). If you are looking for average response time it becomes: (0 + 2 + 2 + 3 + 3) / 5 = 2 – Suyash Singh Bitti Jul 02 '19 at 12:37
19

SJF are two type - i) non preemptive SJF ii)pre-emptive SJF

I have re-arranged the processes according to Arrival time. here is the non preemptive SJF

A.T= Arrival Time

B.T= Burst Time

C.T= Completion Time

T.T = Turn around Time = C.T - A.T

W.T = Waiting Time = T.T - B.T

enter image description here

Here is the preemptive SJF Note: each process will preempt at time a new process arrives.Then it will compare the burst times and will allocate the process which have shortest burst time. But if two process have same burst time then the process which came first that will be allocated first just like FCFS.

enter image description here

Erfan Ahmed
  • 1,536
  • 4
  • 19
  • 34
2

it is wrong. correct will be

P3 P2 P4 P5 P1 0 3 4 6 10 as the correct difference are these

Waiting Time (0+3+4+6+10)/5 = 4.6

Ref: http://www.it.uu.se/edu/course/homepage/oskomp/vt07/lectures/scheduling_algorithms/handout.pdf

Raja
  • 29
  • 1
2

The Gantt charts given by Hifzan and Raja are for FCFS algorithms.

With an SJF algorithm, processes can be interrupted. That is, every process doesn't necessarily execute straight through their given burst time.

P3|P2|P4|P3|P5|P1|P5

1|2|3|5|7|8|11|14

P3 arrives at 1ms, then is interrupted by P2 and P4 since they both have smaller burst times, and then P3 resumes. P5 starts executing next, then is interrupted by P1 since P1's burst time is smaller than P5's. You must note the arrival times and be careful. These problems can be trickier than how they appear at-first-glance.

EDIT: This applies only to Preemptive SJF algorithms. A plain SJF algorithm is non-preemptive, meaning it does not interrupt a process.

user3390629
  • 854
  • 10
  • 17
brthomps
  • 43
  • 6
  • 1
    If burst time of two process is same then FCFS algorithm will be followed. the Gantt chart will be (for pre emptive) p3 - p2 - p3 - p4 - p5 - p1 || 1 - 2 - 3 - 5 - 7 - 11 – Erfan Ahmed Dec 12 '15 at 06:27
  • @ErfanAhmedEmon p3-p2-p3-p4-p5-p1 it will be 1-2-3-5-7-8-11 ? right? – Dayz Nov 01 '17 at 14:19
  • @Dayz I've studied those a long time ago. My apology, can't answer you based on my faint memory right now. – Erfan Ahmed Nov 01 '17 at 14:51