The operating system's job
On This Lesson 11 topics
Lesson Overview
You now know the parts of a computer: a CPU that does the work, RAM that holds what is in use, storage that keeps data, and devices for input and output. But think about your own laptop or phone. You can run a browser, a music player, and a chat app at the same time. They all use the same CPU, the same RAM, and the same storage, and they do not trample on each other. Something is organising that.
That something is the operating system (OS). In this lesson you will learn what it is, what its main jobs are, and where it sits between your programs and the hardware. You will use the kitchen picture from Lesson 2 again: the OS is the kitchen manager.
Why this matters: every program you will ever write runs on top of an operating system and asks it for help constantly. Understanding that relationship explains many things that otherwise look like mysteries: why one program cannot read another's data, why a computer slows down when memory is short, and why backend servers are usually managed through their OS.
This lesson builds on Lessons 1 and 2. The next lesson looks more closely at the programs the OS runs.
Learning Objectives
By the end of this lesson you will be able to:
- Define an operating system and give examples for computers, phones, and servers.
- Describe the layers: hardware, operating system, applications.
- Explain the OS's main jobs: sharing the CPU, managing memory, managing files and storage, talking to devices through drivers, and controlling access.
- Explain how a single CPU can seem to run many programs at once.
- Explain why a program asks the OS for services instead of using the hardware directly.
- Distinguish an operating system from the applications that run on it.
Written Explanation
What is an operating system?
An operating system is the software that manages a computer's hardware and provides common services for the programs that run on it. It is the first big program that starts when you switch the machine on, and it keeps running until you shut down.
Examples you may know:
| Kind of device | Common operating systems |
|---|---|
| Laptops and desktops | Windows, macOS, Linux |
| Phones and tablets | Android, iOS |
| Servers | Many run Linux. Some run Windows Server. |
The OS is not the same as the screen you see (the "desktop" is just one part), and it is not the same as an application. It is the layer that all applications depend on.
The layers
Text version of this diagram
Three layers stacked top to bottom: Applications, Operating system and Hardware. Arrows between Applications and the Operating system show applications asking for services and results coming back. Arrows between the Operating system and Hardware show the operating system using devices through drivers and data coming back.
Applications sit on top. They do not control the hardware directly. When an application needs something, such as reading a file, drawing on the screen, or sending data over the network, it asks the operating system, and the operating system talks to the hardware. A request of this kind is called a system call. You do not need to write them yet. It is enough to know that applications make requests and the OS carries them out.
The core part of the OS that does this most privileged work is called the kernel. People often say "Linux" when they mean the Linux kernel plus the other software around it. We will use the word OS and mention the kernel only when it helps.
Why not let each program use the hardware directly?
Imagine a kitchen where every cook can walk into any other cook's workspace, grab ingredients, and turn off any stove. Chaos. Programs have bugs, and some are written by people you do not trust. If every program could touch the hardware directly, one mistake could crash the whole machine, and a malicious program could read your passwords.
By placing the OS between the programs and the hardware, the machine gets three benefits:
- Sharing. Many programs can use one CPU, one RAM, and one storage device fairly.
- Protection. A program can be kept away from the memory and files of others.
- Simplicity. A programmer asks "save this file" and does not need to know how every kind of disk works.
The main jobs
1. Sharing the CPU (process scheduling)
A running program is called a process (the next lesson explains this properly). A computer usually has many processes but only a few CPU cores. The OS decides which process runs on the CPU and for how long. This is called scheduling.
The OS lets each process run for a very short slice of time, then switches to another, then another, round and round, many times per second. Because the switching is so fast, it looks as if everything runs at once. With several cores, some processes really do run at the same moment, on different cores. This is the cook analogy again: one cook who rapidly moves between dishes, or several cooks working in parallel.
2. Managing memory
The OS is the manager of the counter (RAM). It hands each program the memory it asks for, keeps track of who has what, and takes it back when the program ends. It also makes sure one program cannot read or overwrite another program's memory.
When RAM is short, modern operating systems can temporarily move some data to the much slower storage to make room, and bring it back when needed. This keeps the machine working, but slowly. You saw the effect in Lesson 2, Example 3. The details are in later modules.
3. Managing files and storage
The disk itself only holds raw bytes. The OS adds a file system: the organisation into files and folders with names, sizes, and dates. When a program says "open report.docx", the OS finds where those bytes are on the disk and copies them into RAM.
4. Talking to devices (drivers)
There are thousands of different keyboards, printers, graphics cards, and network adapters. A driver is a small piece of software, usually supplied with the device or the OS, that knows how to talk to one kind of device. The OS uses drivers so applications can use "a printer" without knowing which model it is.
5. Controlling access (users and permissions)
The OS knows who is using the machine and what each user and each program is allowed to do. For example, a normal user cannot change system files, and one user cannot read another user's private files. The details vary between systems.
6. Providing the user interface
The OS also provides a way for people to use the machine: windows and a desktop, a touch interface, or a text command line. Servers often have no screen at all and are controlled over the network using a command line.
Operating system versus application
| Operating system | Application | |
|---|---|---|
| Purpose | Manage the machine and serve programs | Help a person do a task |
| Examples | Windows, macOS, Linux, Android | Browser, spreadsheet, chat app, game |
| How many at a time | One main OS (per machine) | Many at once |
| Depends on | Hardware | The operating system |
An application is written for a particular operating system (or a few of them), which is why some apps exist for Windows and not for macOS, unless the maker builds both versions.
Examples
Example 1: saving a document (simple)
- You press Save in a text editor.
- The editor does not write to the disk directly. It asks the OS: "write these bytes to a file called
notes.txt". - The OS checks that you may write to that folder.
- The OS works out where on the disk the bytes go, and uses the driver to write them.
- The OS tells the editor "done".
The editor needed to know nothing about the disk model.
Example 2: three apps and one CPU (practical)
You listen to music, browse the web, and download a file at the same time on a two-core laptop. That is at least three busy processes and two cores.
The OS slices the time on each core between the processes: a little for the music player, a little for the browser, a little for the downloader, many times per second. You do not notice the switching. The music does not stutter, as long as the machine is not overloaded.
Example 3: one app misbehaves (realistic)
A badly written program tries to read memory that belongs to another program. The OS blocks the attempt and stops the offending program, usually with an error such as "this program has stopped responding". The other program continues normally.
Without the OS in between, the faulty program could have corrupted the other's data. This is the protection benefit in action.
Backend Insight
Backend software depends on the OS in every way described here:
- Servers run an operating system, usually without a screen, and engineers manage them by command line over the network. Learning Linux basics is a standard part of backend work, and the course returns to it later.
- Resources are shared. A server's CPU and RAM are shared by your application and other programs, such as the database and monitoring tools. When RAM runs short, the OS may slow everything down, which is why teams watch memory use.
- Files and permissions matter: a service that cannot read its configuration file because of a permission error is a very common production problem, and it is the OS enforcing its access rules.
- Isolation is the basis for running many applications safely on one machine, and a stepping stone to the idea of containers you will meet later.
When something goes wrong on a server, "what is the OS telling me?" is usually the second question you ask, after "what does the application's own log say?"
Common Mistakes
Mistake 1: Treating the OS as just "the desktop" or "the screen"
The desktop and windows are only the user interface, one of the OS's jobs. Most of what the OS does (scheduling, memory, files, drivers, permissions) is invisible.
Mistake 2: Confusing the OS with an application
- Incorrect: "Chrome is an operating system."
- Correct: "Chrome is an application. Windows, macOS, or Linux is the OS it runs on."
A quick test: could you switch it off and still have a working machine? Without the OS, nothing runs. Without a particular application, everything else still does.
Mistake 3: Believing programs run on the hardware directly
Programs run with the OS in between. They ask it for CPU time, memory, files, and devices, and it decides what they get.
Mistake 4: Thinking a computer runs everything at the same time
Many processes only appear simultaneous because the OS switches between them rapidly. The number of cores limits how many are really running at one instant.
Exercises
Try each exercise yourself before opening the solutions.
Level A: Foundation
A1. What is an operating system? Give two examples for laptops and two for phones.
Show solution A1
A1. An operating system is software that manages a computer's hardware and provides common services to programs. Laptops: Windows, macOS, Linux. Phones: Android, iOS.
A2. Fill in the layers from top to bottom: ______, ______, ______.
Show solution A2
A2. Applications, operating system, hardware.
A3. Which of these is an operating system and which is an application: Android, a music app, Linux, a web browser?
Show solution A3
A3. Android: operating system. Music app: application. Linux: operating system. Web browser: application.
Level B: Application
B1. Name four jobs of the operating system, with one sentence on each.
Show solution B1
B1. Any four of: sharing the CPU between processes (scheduling), managing RAM, managing files and storage with a file system, talking to devices with drivers, controlling access with users and permissions, providing the user interface.
B2. A laptop has one CPU core and is running five apps. Explain, in your own words, how it looks as if they run at the same time.
Show solution B2
B2. The operating system gives each app a very short slice of CPU time, then switches to the next, again and again, many times a second. The switching is so fast that it looks simultaneous, even though only one app runs on the core at any single instant.
B3. Why should a program not be allowed to read another program's memory? What does the OS do about it?
Show solution B3
B3. A program has bugs or may be malicious. If it could read or change another program's memory, it could corrupt data, crash it, or steal secrets. The OS keeps each program's memory separate and stops a program that tries to touch memory it does not own.
Level C: Challenge
C1. Describe step by step what happens when an app asks to open a file. Use the words: application, operating system, file system, driver, storage, RAM.
Show solution C1
C1. The application asks the operating system to open the file. The operating system's file system looks up where the file's bytes are on the storage device. It uses the driver for that device to read the bytes. It copies them into RAM. It tells the application that the file is open, and the application works on the copy in RAM.
C2. A server runs a web application and a database. Both are slow. Explain how sharing the CPU and RAM through the OS can cause this, and what you would check first.
Show solution C2
C2. Both programs compete for the same CPU time and RAM. If one of them uses too much, the other has less, and if RAM is short the OS may move data to slow storage, slowing everything. First check CPU use and memory use per process to see which one is consuming the resources (the next lesson shows how).
Mini Challenge
Find out which operating system and which version your own computer or phone runs (look in its Settings or About screen). Then write a short note covering:
- The name and version of the OS.
- Two applications you use, and the OS each depends on.
- One example of something the OS did for you today without your noticing (for example, saving a file, switching between apps, or connecting to Wi-Fi), described in terms of the jobs in this lesson.
Check your work: you did not list an application as an OS, and your example matches one of the jobs (scheduling, memory, files, drivers, permissions, interface).
Summary & Next Lesson
Key takeaways
- The operating system manages the hardware and provides common services to applications.
- The layers are hardware at the bottom, the OS in the middle, applications on top.
- The OS's main jobs: sharing the CPU, managing memory, managing files, using drivers for devices, controlling access, and providing the user interface.
- A single CPU core runs one process at a time, and the OS switches fast enough to give the feeling of running many.
- Applications ask the OS for what they need instead of using the hardware directly.
Next lesson
The OS runs programs. But what exactly is a "running program"? The next lesson, "Applications and processes", explains the difference between a program, an application, and a process, and shows you how to see the processes on your own machine with Task Manager or Activity Monitor.
Self-check
- What is the operating system's role in one sentence?
- Name three jobs of the OS.
- Why do many programs appear to run at the same time on one CPU core?
- Is a browser an OS?
- Why do programs ask the OS to use a disk instead of using it directly?
Show answers
- It manages the hardware and provides common services to programs.
- For example: scheduling the CPU, managing memory, managing files, drivers, permissions.
- The OS switches between them in very short time slices, very fast.
- No, it is an application that runs on an OS.
- So that programs can be protected from each other, share the hardware fairly, and do not have to know the details of every device.
References
- Operating-system course notes commonly describe an OS as system software that manages hardware and software resources and provides common services for programs, with process management, memory management, file systems, and device management as core functions. This lesson follows that standard definition. A primary textbook source (for example the free Operating Systems: Three Easy Pieces) is recommended for deeper reading; its text could not be machine-read during drafting, so no passage from it is quoted here.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.