Time Slicing Concepts
Allowing multitasking from one central processing unit
Many users may be logged into the system. One user may be using an editor to modify a file, another may be compiling a C program using the 'gcc' command, another may issue an 'lpr' command to send a file to the printer, while yet another user may issue a 'ps' command to view the properties of a subset of the processes running on the system. Multitasking makes each user feel as though he or she is the only one using the computer. Each process gets full access to the Central Processing Unit or CPU of the computer for a very short period of time. The time slice of a process typically ranges in hundredths of a second.
Depending on how busy the system is at a point of time (or its load), a process may get several time slices per second. After it has executed for its time slice, the OS checks if other processes need a turn; all processes take turns on the CPU in this manner. However, if a process needs to wait for an event (like the availability of a device, keyboard input from the user etc., completion of file read from/write to disk etc.), it 'sleeps' until the event occurs and allows other processes to execute during its turn. If a device like a keyboard, printer, or clock needs immediate access to the Operating System, an 'interrupt' is signaled to the CPU. This stops an executing process and allows the device access to the CPU if the priority of the executing process is less than that of the interrupt (every process is associated with a priority).
The state of each register (low level data holders) at the end of a process's time slice, the internal state of the CPU and so on are stored as part of the process context. This ensures that the process starts running at the exact place it left off in the previous time slice.