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.
|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.
- 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.
- 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.
Attention reader! Don’t stop learning now. 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.
- Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
- Difference between Arrival Time and Burst Time in CPU Scheduling
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
- Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
- Shortest Job First CPU Scheduling with predicted burst time
- Priority CPU Scheduling with different arrival time - Set 2
- Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
- Longest Remaining Time First (LRTF) CPU Scheduling Program
- Program for FCFS CPU Scheduling | Set 1
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- Program for FCFS CPU Scheduling | Set 2 (Processes with different arrival times)
- CPU Scheduling in Operating Systems
- Operating Systems | CPU Scheduling | Question 1
- Operating Systems | CPU Scheduling | Question 2
- Program for Priority CPU Scheduling | Set 1
- Multilevel Queue (MLQ) CPU Scheduling
- Highest Response Ratio Next (HRRN) CPU Scheduling
- Selfish Round Robin CPU Scheduling
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.