3/16/2021 0 Comments Sjf Scheduling Java
Since the currently executing process is the one with the shortest amount of time remaining by definition, and since that time should only reduce as execution progresses, processes will always run until they complete or a new process is added that requires a smaller amount of time.P1 waiting time: 4-2 2 P2 waiting time: 0 The average waiting time(AWT): (0 2) 2 1.If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contributegeeksforgeeks.org.
See your article appearing on the GeeksforGeeks main page and help other Geeks. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready. The choice of preemptive and non preemptive arises when a new process arrives at the ready queue and a previous process is not finished and is being executed. If the next CPU burst of new process is shorter than current executing process, then in preemptive version, it will stop that process and will start executing the newly arrived process. While, in non preemptive version of SJF, even if the arriving process is shorter than currently executing process, current process is not stopped. After the current process finishes, then the new process gets in the queue. This is the key difference between preemptive and preemptive version of SJF. The current state of the process is saved by the context switch and the CPU is given to another process. Note If 2 processes have same execution time, then jobs are based on First Come First Serve Basis. SJF Preemptive Example Lets understand SJF Scheduling with the help of an example. P2 has 4ms, so as P2 is shorter, P1 is preempted and P2 process starts executing. At this time, P1(remaining time) 5ms, P2(remaining time ) 3 ms, P3 2ms. Since P3 is having least burst time, P3 is executed. At ( t 3ms ), P4 comes, At this time, P1 5ms, P2 3ms, P3 1ms, P4 3ms. Since P4 does not have short burst time, so P2 continues to execute. Now, remaining tasks are P1 5ms, P2 3ms, P4 3ms. As,P2 and P4 have same time, so the task which came first will be executed first. At ( t 7ms ),P4 gets executed for 3ms. ![]() Waiting time P1 waiting time (10 -1) 9ms P2 waiting time (4-1) 3ms P3 waiting time 2ms P4 waiting time 7ms The average waiting time is ( 9 1 2 7)4 4.75 Disadvantages It has the same disadvantages as non-preemptive version of SJF. Here also process with larger burst time may experience process starvation, which could be prevented with aging. Just type following details and we will send you a link to reset your password.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |