Multitasking
Multitasking is an operating system's ability to keep several tasks in progress at the same time, switching the processor among them so quickly that a user can browse the web, play music and download a file as though all were running at once. On a machine with a single processor core the overlap is an illusion created by rapid alternation, and on a multicore machine it is a mixture of real parallel execution and the same alternation, because there are almost always more runnable tasks than cores.
Time slicing is the mechanism behind the illusion: the scheduler gives each runnable task a short turn on the processor, called a quantum or time slice, typically a few milliseconds, and then moves on to the next. The idea grew out of time-sharing research of the early 1960s, notably Fernando Corbato's Compatible Time-Sharing System (CTSS) at MIT, first demonstrated in 1961, which let many users share one expensive computer interactively. Each switch requires a context switch, in which the operating system saves the current task's registers and program counter, loads the saved state of the next task, and resumes it. Switching is not free: it costs time and disturbs the CPU cache, which is why a scheduler balances responsiveness against overhead rather than switching as often as possible.
Preemptive and cooperative multitasking differ in who decides when a task must give up the processor, and that single difference determines how robust a system is. In preemptive multitasking, a hardware timer interrupts the running task and the kernel forcibly takes control, so a buggy or greedy program cannot monopolize the machine. Unix, Windows NT (1993), Windows 95 for 32-bit programs, Linux and modern macOS and Android all work this way. In cooperative multitasking, each program must voluntarily yield by calling the system at appropriate moments; Windows 3.x and the classic Mac OS (until Mac OS X in 2001) worked this way, and a single program stuck in a loop could freeze the whole computer. Cooperative scheduling survives today inside languages and runtimes, as in coroutines and async-await, where the cost of switching is low and the code's own awaits mark the yield points.
Multitasking is a concept about scheduling work, and it is related to but distinct from the units being scheduled and from true parallelism. Processes and threads, covered in their own entries, are the things a scheduler switches among: a process has its own address space and resources, while threads share one. Concurrency means several tasks are in progress during the same period; parallelism means several are literally executing at the same instant on different cores, which requires multicore or multiple processors. A scheduler also uses priorities, and tasks that spend most of their time waiting for input, disk or the network are cheap to keep around, because a waiting task is simply skipped until its event arrives.
Common misconceptions are that opening more programs always slows a computer and, conversely, that multitasking makes a computer do more total work. Idle or waiting programs cost almost nothing in processor time, but each consumes memory, and once physical memory runs out the system starts paging to disk and performance collapses, a condition called thrashing. Because switching has overhead, running many CPU-bound jobs on one core finishes each of them later, not sooner, than running them in turn. The practical relevance is everywhere: web servers handle thousands of connections by multiplexing them, data pipelines overlap loading and computation, and machine learning training keeps a GPU busy by preparing the next batch on the CPU while the current one is processed.
Read multitasking as the scheduler's promise of fairness and responsiveness: by slicing processor time, saving and restoring each task's state, and (in the preemptive model) reserving the right to interrupt, the operating system lets many independent activities share limited hardware without any one of them being able to stall the rest.