Foundations: What an Operating System Is

time-sharing (multitasking)

Time-sharing is multiprogramming taken one decisive step further: instead of only switching the CPU when a program happens to wait, the OS switches rapidly and on purpose, giving each program a tiny slice of CPU time in quick rotation. The effect is the illusion that many programs — and on shared machines, many users — are all running at the same time, each getting prompt attention. Picture a chess master playing twenty opponents at once, walking the row and making one move at each board: each player feels attended to, because the master comes back around fast enough.

The key addition over plain multiprogramming is the timer interrupt. The OS sets a hardware timer to fire after a short interval (a time slice, often a few milliseconds). When the timer goes off, control jumps into the OS even if the running program did not want to stop, and the scheduler may switch to another program — this is preemption. Each program runs for its slice, is paused with its state saved, and another runs; the rotation cycles so quickly (tens of times a second) that to a human everything appears simultaneous and responsive. This is what makes a single computer feel like it is running your editor, your browser, and your music all at once. The word multitasking is the everyday name for the same idea.

Time-sharing is why modern computing feels interactive rather than like submitting a job and waiting. But there is an honest cost: switching between programs takes real work (saving and restoring state, a context switch), so slices cannot be made arbitrarily tiny — too small and the machine spends more time switching than computing. And time-sharing creates the illusion of simultaneity, which is not the same as true parallelism: on a single CPU core only one program runs at any instant; they merely take turns very fast. Real simultaneous execution needs multiple cores, a separate idea (parallelism).

On a single-core machine your editor, browser, and music player all seem to run together. In reality the OS gives each a few-millisecond slice in turn — type a key, the editor gets a slice; a song frame is due, the player gets one — cycling so fast it feels simultaneous.

Rapid turn-taking on one core creates the illusion of running all at once.

Time-sharing gives the illusion of simultaneity, not true parallelism — on one core, programs interleave rather than run at the same instant. Slices also cannot shrink forever: too small and switching overhead dominates.

Also called
multitaskinginteractive computing多工處理分時