Open In App
Related Articles

Time Slicing in CPU scheduling

Like Article
Save Article
Report issue
CPUs kernel doesn’t simply distribute the entirety of our PCs’ resources to single process or service. CPU is continuously running many processes that are essential for it to operate, so our kernel needs to manage these processes without moment’s delay. When program needs to run, process must be created for it. This process needs to have important resources like RAM and CPU. The kernel schedules time periods for CPU to perform commands and instructions in process. Be that as it may, there’s just single CPU and numerous processes. How does CPU outstand to execute different processes without moment’s delay? It does it by executing processes one by one, individually by time slice. A time slice is short time frame that gets assigned to process for CPU execution. Time slice : It is timeframe for which process is allotted to run in preemptive multitasking CPU. The scheduler runs each process every single time-slice. The period of each time slice can be very significant and crucial to balance CPUs performance and responsiveness. If time slice is quite short, scheduler will take more processing time. In contrast, if the time slice is too long, scheduler will again take more processing time.
When process is allotted to CPU, clock timer is set corresponding to time slice.
  • If the process finishes its burst before time slice, CPU simply swaps it out like conventional FCFS calculation.
  • If the time slice goes off first, CPU shifts it out to back of ongoing queue.
The ongoing queue is managed like circular queue, so, after all processes are executed once, scheduler executes first process again and then second and so forth. Example –
Process Queue Required burst time by process(ms)
We have three processes(P1, P2, P3) with their corresponding burst times(1ms, 4ms, 5ms). A rule of thumb is that 80% of CPU bursts should be smaller than the time quantum. Considering time slice of 2ms. Here’s how CPU manages it by time slicing.

time-slicing approach for process management

Advantages :
  • Fair allocation of CPU resources.
  • It deals all process with equal priority.
  • Easily implementable on the system.
  • Context switching method used to save states of preempted processes
  • gives best performance in terms of average processing time.
Disadvantages :
  • If the slicing time is short, processor output will be delayed.
  • It spends time on context switching.
  • Performance depends heavily on time quantum.
  • Priorities can’t be fixed for processes.
  • No priority to more important tasks.
  • Finding an appropriate time quantum is quite difficult.

Last Updated : 24 Aug, 2020
Like Article
Save Article
Share your thoughts in the comments
Similar Reads