This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Preemption" computing – news ·newspapers ·books ·scholar ·JSTOR(February 2009) (Learn how and when to remove this message) |
Incomputing,preemption is the act performed by an externalscheduler — without assistance or cooperation from the task — of temporarilyinterrupting anexecutingtask, with the intention of resuming it at a later time.[1]: 153 This preemptive scheduler usually runs in the most privilegedprotection ring, meaning that interruption and then resumption are considered highly secure actions. Such changes to the currently executing task of aprocessor are known ascontext switching.
In any given system design, some operations performed by the system may not be preemptable. This usually applies tokernel functions and serviceinterrupts which, if not permitted torun to completion, would tend to producerace conditions resulting indeadlock. Barring the scheduler from preempting tasks while they are processing kernel functions simplifies the kernel design at the expense ofsystem responsiveness. The distinction betweenuser mode andkernel mode, which determines privilege level within the system, may also be used to distinguish whether a task is currently preemptable.
Most modern operating systems havepreemptive kernels, which are designed to permit tasks to be preempted even when in kernel mode. Examples of such operating systems areSolaris 2.0/SunOS 5.0,[2]Windows NT,Linux kernel (2.5.4 and newer),[3]AIX and someBSD systems (NetBSD, since version 5).
The termpreemptive multitasking is used to distinguish amultitasking operating system, which permits preemption of tasks, from acooperative multitasking system wherein processes or tasks must be explicitly programmed toyield when they do not need system resources.
In simple terms: Preemptive multitasking involves the use of aninterrupt mechanism which suspends the currently executing process and invokes ascheduler to determine which process should execute next. Therefore, all processes will get some amount of CPU time at any given time.
In preemptive multitasking, the operating systemkernel can also initiate acontext switch to satisfy thescheduling policy's priority constraint, thus preempting the active task. In general, preemption means "prior seizure of". When the high-priority task at that instance seizes the currently running task, it is known as preemptive scheduling.
The term "preemptive multitasking" is sometimes mistakenly used when the intended meaning is more specific, referring instead to the class of scheduling policies known astime-shared scheduling, ortime-sharing.
Preemptive multitasking allows the computer system to more reliably guarantee each process a regular "slice" of operating time. It also allows the system to rapidly deal with important external events like incoming data, which might require the immediate attention of one or another process.
At any specific time, processes can be grouped into two categories: those that are waiting for input or output (called "I/O bound"), and those that are fully utilizing the CPU ("CPU bound"). In early systems, processes would often "poll" or "busy-wait" while waiting for requested input (such as disk, keyboard or network input). During this time, the process was not performing useful work, but still maintained complete control of the CPU. With the advent of interrupts and preemptive multitasking, these I/O bound processes could be "blocked", or put on hold, pending the arrival of the necessary data, allowing other processes to utilize the CPU. As the arrival of the requested data would generate an interrupt, blocked processes could be guaranteed a timely return to execution.
Although multitasking techniques were originally developed to allow multiple users to share a single machine, it became apparent that multitasking was useful regardless of the number of users. Many operating systems, from mainframes down to single-user personal computers and no-usercontrol systems (like those inrobotic spacecraft), have recognized the usefulness of multitasking support for a variety of reasons. Multitasking makes it possible for a single user to run multiple applications at the same time, or to run "background" processes while retaining control of the computer.
The period of time for which a process is allowed to run in a preemptive multitasking system is generally called thetime slice orquantum.[1]: 158 The scheduler is run once every time slice to choose the next process to run. The length of each time slice can be critical to balancing system performance vs process responsiveness - if the time slice is too short then the scheduler itself will consume too much processing time, but if the time slice is too long, processes will take longer to respond to input.
Aninterrupt is scheduled to allow theoperating systemkernel to switch between processes when their time slices expire, effectively allowing the processor's time to be shared among a number of tasks, giving the illusion that it is dealing with these tasks in parallel (simultaneously). The operating system which controls such a design is called a multi-tasking system.
Today, nearly all operating systems support preemptive multitasking, including the current versions ofWindows,macOS,Linux (includingAndroid),iOS andiPadOS.
An early microcomputer operating system providing preemptive multitasking wasMicroware'sOS-9, available for computers based on theMotorola 6809, including home computers such as theTRS-80 Color Computer 2 when configured with disk drives,[4] with the operating system supplied by Tandy as an upgrade.[5]Sinclair QDOS[6]: 18 andAmigaOS on theAmiga were also microcomputer operating systems offering preemptive multitasking as a core feature. These both ran onMotorola 68000-familymicroprocessors without memory management. Amiga OS useddynamic loading of relocatable code blocks ("hunks" in Amiga jargon) to multitask preemptively all processes in the same flat address space.
Early operating systems forIBM PC compatibles such asMS-DOS andPC DOS, did not support multitasking at all, however alternative operating systems such asMP/M-86 (1981) andConcurrent CP/M-86 did support preemptive multitasking. OtherUnix-like systems includingMINIX andCoherent provided preemptive multitasking on 1980s-era personal computers.
LaterMS-DOS compatible systems natively supporting preemptive multitasking/multithreading includeConcurrent DOS,Multiuser DOS,Novell DOS (later calledCaldera OpenDOS andDR-DOS 7.02 and higher). SinceConcurrent DOS 386, they could also run multiple DOS programs concurrently invirtual DOS machines.
The earliest version of Windows to support a limited form of preemptive multitasking wasWindows/386 2.0, which used theIntel 80386'sVirtual 8086 mode to run DOS applications invirtual 8086 machines, commonly known as "DOS boxes", which could be preempted. InWindows 95, 98 and Me, 32-bit applications were made preemptive by running each one in a separate address space, but 16-bit applications remained cooperative for backward compatibility.[7] In Windows 3.1x (protected mode), the kernel and virtual device drivers ran preemptively, but all 16-bit applications were non-preemptive and shared the same address space.
Preemptive multitasking has always been supported byWindows NT (all versions),OS/2 (native applications),Unix andUnix-like systems (such asLinux,BSD andmacOS),VMS,OS/360, and many other operating systems designed for use in the academic and medium-to-large business markets.
Early versions of theclassic Mac OS did not support multitasking at all, with cooperative multitasking becoming available viaMultiFinder inSystem Software 5 and then standard inSystem 7. Although there were plans to upgrade the cooperative multitasking found in the classic Mac OS to a preemptive model (and a preemptive API did exist inMac OS 9, although in a limited sense[8]), these were abandoned in favor ofMac OS X (now called macOS) that, as a hybrid of the old Mac System style andNeXTSTEP, is an operating system based on theMach kernel and derived in part fromBSD, which had always provided Unix-like preemptive multitasking.