Watch on Instagram

Code Bytes · "How Computers Work" · Episode 6 · Software layers

What an operating system does

An operating system (OS), like Windows, macOS or Linux, is the software that sits between your apps and the hardware. It hands out memory, keeps files on storage, controls devices like the keyboard and screen, and shares the CPU by giving apps tiny turns, so fast they seem to run at once.

Posted · About a 1 minute watch, 3 minute read · Take the quiz

Who's in between?

Your apps (a music player, a web browser, a game) never talk to the hardware directly. They don't move data around in RAM themselves or control the screen pixel by pixel. Something sits in between them and the hardware: the operating system, or OS.

You have used one already. Windows, macOS and Linux are operating systems for desktop and laptop computers.

A restaurant with a manager

Think of a restaurant:

  • The apps are the customers. They want things.
  • The hardware (the CPU, RAM and storage) is the kitchen. It does the real work.
  • The OS is the manager standing between them. Customers don't walk into the kitchen; they ask, and the manager makes it happen.

What the OS does

  1. Hands out memory. Each running app gets its own slice of RAM (the computer's working memory, from Code Bytes EP29).
  2. Saves files. It keeps your files on storage and finds them again later.
  3. Controls devices. It talks to the keyboard, the screen and other devices, so every app doesn't have to.
  4. Shares the CPU. Many apps want the CPU at once. The OS gives each one a tiny turn, then switches to the next, many times a second. The turns are so fast that the apps seem to run at the same time.

Turns in Python

This Python loop doesn't really schedule anything. It just acts out one round of turns by printing each app's name in order:

``python apps = ["music", "browser", "game"] for app in apps: print(app) ``

`` music browser game ``

The for loop takes each item in the list apps, one at a time and in order, and runs print(app) for it. In a computer, the round then starts again, over and over.

Even that print line leans on the OS: Python hands the words to the operating system, and the OS shows them in your terminal window.

Try it yourself

Open any free online Python editor (search "online Python") and run:

``python jobs = ["save file", "play sound"] for job in jobs: print("OS is doing:", job) ``

You should see:

`` OS is doing: save file OS is doing: play sound ``

Try adding a third job to the list, like "show picture", and run it again: the loop gives it a turn too, without changing anything else.

Good to know

  • Every snippet on this page was run with Python 3 (3.13) and printed exactly what is shown.
  • "Taking turns" is a simplification. Modern CPUs have several cores that really do run programs at the same time, and the OS doesn't simply go round in a fixed circle: it picks who goes next by priority and by what each program is waiting for. The music, browser and game apps here are just an illustration.
  • Apps ask the OS for help through special requests called system calls. When Python prints, it makes one of these requests to write the words out.
  • The OS uses small pieces of software called drivers to talk to each kind of device, like a keyboard or a screen.
  • Phones have operating systems too, such as Android and iOS.

Answer to the comment question

Music, browser, game take turns in that order, over and over. Whose is the fifth turn?

The browser's.

The turns go music (1), browser (2), game (3), then the round starts again: music (4), browser (5). You can check it in Python 3 by repeating the list twice and picking the fifth item (Python counts from 0, so the fifth item is at position 4):

``python apps = ["music", "browser", "game"] turns = apps * 2 print(turns[4]) ``

`` browser ``

Test your knowledge

Quick quiz: What an operating system does

4 multiple-choice questions. Pick one answer for each, then check how you did.

1Where does the operating system sit?
2In the restaurant picture, what is the OS?
3How can many apps seem to run at once on the CPU?
4What does this print? for app in ["music", "game"]: print(app)

Sources

  • Britannica, "operating system": the OS is the program that manages a computer's resources, such as memory, storage, devices and processor time, for the other programs
  • Wikipedia, "Operating system": examples such as Windows, macOS and Linux; programs ask the OS for services instead of using the hardware directly
  • Wikipedia, "Time-sharing": the OS switches the CPU between programs in short turns so they seem to run at the same time
  • Python Software Foundation, "for Statements": a for loop runs its body once for each item in a list, in order

Video transcript

Your apps never talk to the hardware directly. So who's in between?

That's the operating system, or OS, like Windows, macOS or Linux.

Think of a restaurant. Apps are customers, the hardware is the kitchen, and the OS is the manager between them.

The OS hands out memory, saves files, and controls devices like the keyboard and screen.

It also shares the CPU. Apps take tiny turns, so fast they seem to run at once.

This Python loop acts out one round of turns: music, browser, game. Then the round starts again.

Even your print line asks the OS to show the words.

Music, browser, game take turns in that order, over and over. Whose is the fifth turn? Comment your answer below!

That's your byte.

More from "How Computers Work"

All "How Computers Work" lessons