Time slice is the maximum length of time that a process can monopolize the CPU. Once that time elapses the process is suspended and the CPU given to another task at the same run priority, or if no other process at the same run priority is waiting for the CPU, then to the first process waiting at the next lower run priority.
Now if a process at a higher run priority wants the CPU (perhaps it was waiting for an IO to complete and the IO has completed) then the lower run priority process is interrupted before its time slice has expired.
So an interactive process, which runs at a higher priority, generally does little CPU work before it gives up the CPU voluntarily because it is waiting for a non-CPU activity to complete, so it has less involuntary switching because the time slice has expired. Thus it has a shorter time slice.
Batch, on the other hand, tends to need more CPU and gets a longer time slice, but runs at a lower priority.
A process does not have to get to the end of it's time slice before it is forced to give up the CPU. Requesting an IO, for example, voluntarily surrenders the CPU.
As an Amazon Associate we earn from qualifying purchases.
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.