Nepedia
Back to Discover
Advanced Reader
💻

Preemption (computing)

technology Maturity 9-11 Next article →

In computing, preemption is a method used to manage how a processor handles different tasks. It is the act of an external scheduler temporarily interrupting a running task. This interruption happens without any assistance or cooperation from the task itself. The scheduler intends to resume the interrupted task at a later time. This process is highly secure because the scheduler usually runs in the most privileged protection ring. When the processor changes which task it is currently executing, this is known as context switching. Preemption is essential for modern multitasking, ensuring that no single process holds the processor hostage.

To understand how this works, we must look at the mechanism of the scheduler and interrupts. In a preemptive multitasking system, the operating system uses an interrupt mechanism to function. This interrupt suspends the currently executing process. Once suspended, the scheduler is invoked to determine which process should execute next. This ensures that every process receives some amount of CPU time. The scheduler can also initiate a context switch to satisfy priority constraints. If a high-priority task needs to run, it can seize control from the current task. This specific type of scheduling is called preemptive scheduling.

Processes are often categorized by how they use system resources. Some tasks are known as CPU bound because they fully utilize the processor. Other tasks are called I/O bound, meaning they are waiting for input or output. This might include waiting for a keyboard, a disk, or network input. In early computing systems, I/O bound processes would often "poll" or "busy-wait." This meant they maintained complete control of the CPU while doing no useful work. With preemption, these processes can be "blocked" or put on hold. This allows the CPU to work on other tasks until the necessary data arrives via an interrupt.

Managing these tasks requires a careful balance of time. The period a process is allowed to run is called a time slice or a quantum. The scheduler runs once every time slice to choose the next process. The length of this slice is critical for system performance. If the time slice is too short, the scheduler consumes too much processing time. If the time slice is too long, processes take longer to respond to user input. By using interrupts when time slices expire, the system shares the processor among many tasks. This creates the illusion that the computer is dealing with all tasks in parallel.

System design also involves different levels of privilege, known as user mode and kernel mode. In some designs, certain operations are not preemptable. This often applies to kernel functions and service interrupts. If these are not allowed to run to completion, they might produce race conditions. These conditions can lead to a deadlock, where the system stops working. Some designs simplify the kernel by barring preemption during these functions, though this reduces responsiveness. However, most modern operating systems use preemptive kernels. These are designed to permit tasks to be preempted even while in kernel mode.

The history of multitasking shows a shift from cooperative to preemptive models. In cooperative multitasking, processes must be explicitly programmed to yield control. Early microcomputer systems like Microware's OS-9 provided preemptive multitasking. Sinclair QDOS and AmigaOS were also early examples that used preemption as a core feature. These systems often ran on Motorola 68000-family microprocessors. In contrast, early IBM PC systems like MS-DOS did not support multitasking at all. However, other systems like MP/M-86 supported it as early as 1981. Windows eventually introduced limited preemption with Windows/386 2.0 using virtual 8086 machines.

Today, preemptive multitasking is a standard feature in almost all major operating systems. This includes Windows NT, all versions of Linux, and the Linux kernel from version 2.5.4 and newer. It is also found in Solaris 2.0, AIX, and various BSD systems like NetBSD. Apple's operating systems, such as macOS and iOS, are based on the Mach kernel and derive from BSD. Even Android uses this technology because it is based on Linux. This widespread support allows a single user to run multiple applications at once. It also allows the system to handle important external events rapidly, making modern computing reliable and efficient.

710 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.