Find a course

Module 2: How Computers WorkLesson 5 of 1212 min

Operating Systems and Software

Learn what an operating system does, how programs share one processor, and how compilers and interpreters turn readable code into machine instructions.

Step 1 of 13Learn

The manager you never see

Right now your device is probably running a browser, a music app, a messaging app, background updates and dozens of system services, all apparently at once, all sharing one processor, one pool of memory and one storage drive. Nobody is fighting over the hardware because an operating system (OS) is in charge.

Windows, macOS, Linux, Android and iOS are all operating systems. An OS has several big jobs:

  • Process management: decides which program runs on which CPU core, and for how long.
  • Memory management: gives each program its own region of RAM and stops programs from reading or overwriting each other's memory.
  • File systems: organizes storage into files and folders, so programs can say "open report.pdf" instead of "read blocks 48,211 to 48,560."
  • Device drivers: small programs that let the OS talk to specific hardware, from printers to graphics cards.
  • Security and users: controls who can log in and which programs may access the camera, files or network.
  • User interface: the desktop, home screen or command line you interact with.

All of this is abstraction once more. Apps don't need to know which brand of SSD you have; they ask the OS to save a file, and the OS handles the details.

Step 2 of 13Practice · Match the pairs

Match each operating system job with an example.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Process management
  2. Memory management
  3. File system
  4. Device driver
  5. Security

Step 3 of 13Learn

Doing many things at once

A single CPU core can only execute one instruction stream at a time. So how can you stream music while typing an essay?

The OS uses time slicing. Each running program is a process. The OS's scheduler gives one process a tiny slice of time, a few milliseconds, then pauses it, saves its state (register values, program counter) and switches to another. This happens hundreds of times per second, far too fast for you to notice, so everything appears to run simultaneously. This is called concurrency.

With multiple cores, programs can also run in true parallel: four cores really can run four instruction streams at the same moment.

The scheduler juggles priorities. Your music must never stutter, so audio gets a high priority; a background backup can wait. When a program is waiting, for example for a file to load or a network reply to arrive, the scheduler gives its time to something else instead of letting the CPU sit idle.

When one app freezes, the rest of the system usually keeps working, because the OS isolates processes from each other. That's also why your task manager can list every process and force a stuck one to quit.

Step 4 of 13Diagram

Time slicing on one core

Each slice lasts a few milliseconds, so the switching is far too fast for you to notice.

Time slicing on one coreCycle diagram: Browser → Music app → Messaging app → System services.One CPU coreBrowserMusic appMessaging appSystemservices

Tap a shape with to see more.

Browser

Runs for a few milliseconds, then is paused and its state saved.

Music app

Gets a turn, decodes a bit more audio.

Messaging app

Checks for new messages.

System services

Updates, networking, indexing.

Step 5 of 13Practice · True or false

On a computer with a single CPU core, programs that appear to run at the same time are actually taking turns very quickly.

Step 6 of 13Learn

From code to machine instructions

CPUs only understand machine code: binary instructions specific to their design. Humans write in high-level languages like Python, JavaScript, Java or C, which are readable and portable. Something must translate.

There are two main approaches.

A compiler translates the whole program into machine code before it runs, producing an executable file. C, C++, Rust and Go are typically compiled. Compiled programs usually run fast, and many errors are caught at compile time, but you have to recompile after every change and for each type of processor.

An interpreter reads the source code and executes it statement by statement while the program runs. Python is commonly interpreted. This makes it quick to experiment and easy to run the same code on different machines, but pure interpretation is slower.

Modern languages often mix both. Java compiles to an intermediate bytecode run by a virtual machine. JavaScript engines in browsers use just-in-time (JIT) compilation: they start interpreting immediately, notice which code runs often, and compile that part to fast machine code on the fly.

Between machine code and high-level languages sits assembly language, a human-readable version of machine instructions, like ADD R1, R2. Very few programmers write it today, but it shows how directly code maps onto the fetch-decode-execute cycle.

Step 7 of 13Compare

Compiler vs. interpreter

AspectCompilerInterpreter
When translation happensBefore the program runs, all at onceWhile the program runs, statement by statement
OutputAn executable file of machine codeNo separate file; the code runs directly
Typical speedFaster at run timeSlower at run time
Feedback while developingMany errors reported before runningErrors appear when the faulty line is reached
Typical languagesC, C++, Rust, GoPython, Ruby; JavaScript with JIT

Step 8 of 13Practice · Choose one

Ana changes one line of a large C program and must wait a few seconds before she can run it again. Python developers on her team can rerun immediately. Why?

Step 9 of 13Note

Step 10 of 13Diagram

The software stack

The software stackLayer diagram: You, Applications, Operating system, Hardware.YouApplicationsOperating systemHardware

Tap a shape with to see more.

You

You click, tap and type.

Applications

Ask the operating system for files, memory, network and screen.

Operating system

Manages and shares the hardware safely between programs.

Hardware

Runs machine code: CPU, memory, storage, devices.

Step 11 of 13Note

Step 12 of 13Practice · Sort into groups

Sort each item: application software or system software?

Tap an item, then tap its group (or drag it there).

Step 13 of 13Practice · Select all that apply

Which of these are jobs of an operating system? Select all that apply.

Select all that apply.