Skip to content

Operating Systems: Hiring a "Chief Manager" for Your Computer

Preface

With a perfect CPU and unlimited memory, is a computer ready to use? In the previous chapter, we witnessed how transistors combine to form a powerful CPU. But even with the most top-tier hardware, if you let it work directly, even displaying a single letter on screen would require writing hundreds of lines of obscure machine instructions. Not only is this cumbersome, it's also extremely dangerous — one small mistake and your code could overwrite someone else's data.

To solve these nightmares, the Operating System (OS) was born. It is the most magnificent layer of "software" standing between you and the cold hardware. In this chapter, we'll set aside obscure code and use accessible analogies to see how this "super butler" tames chaotic hardware into submission.

What will you learn from this article?

After completing this chapter, you will gain:

  • Troubleshooting ability: When encountering "program frozen" or "out of memory" issues, analyze causes from the operating system level
  • Deeper terminology understanding: Understand what problems "multiprocessing," "virtual memory," and "file permissions" solve
  • Systems thinking: Understand that programs don't run in isolation — they interact closely with the OS, other processes, and hardware resources
  • Foundation for further learning: Build a foundation for concurrent programming, system tuning, and container technology
ChapterContentCore Concepts
Chapter 1Process ManagementCPU time-division multiplexing, round-robin scheduling
Chapter 2Memory ManagementVirtual memory, paging mechanism
Chapter 3File SystemsFile organization, directory structure

0. Big Picture: What Happens Without an Operating System?

Imagine you open a "computing factory" (your computer) with immense potential. The factory has one all-powerful, tireless top worker (CPU), a vast warehouse (memory), and countless shipping containers (hard drives).

If you don't hire a factory manager (operating system):

  1. CPU Monopoly Crisis: The CPU can only do one thing at a time. If someone is using it to play music, anyone else wanting to browse the web? Sorry — everyone must wait until the music player voluntarily yields the CPU.
  2. Memory Stampede Accidents: WeChat and a game are both using the warehouse (memory). Without a security guard designating areas, the game might accidentally place its equipment data in WeChat's box, causing WeChat to crash instantly.
  3. Hard Drive Maze: The hard drive hardware is just giant discs etched with 0s and 1s. To find yesterday's photo, you'd have to precisely remember it's stored at "platter 1, track 56, sector 8." Nobody can memorize such anti-human coordinates.
📱 Applications
🎵💬🎮
🖥️ Operating System
Schedule CPU
Allocate memory
Manage files
💾 Hardware
🧠 CPU💾 Memory💿 Disk
The application is ready to send a request...

To solve these three nightmares, the operating system deploys its three magic weapons: process management, memory management, and file systems.


1. Process Management: CPU Time-Division Multiplexing

When you use your computer, you often have WeChat running, music playing, and typing all at the same time. But if your computer actually has only one CPU core, how does it do all three things simultaneously?

The answer: It doesn't do them simultaneously. Instead, the operating system performs frantic "time management."

⏱️ The CPU switches tasks so fast you cannot feel it
CPU
💬Chat
Time slice: 0ms
💬
Chat
Running
🎵
Music
Waiting
🌐
Browser
Waiting
💡 Principle: The CPU switches processes every 100ms. It happens so quickly that it feels like everything runs at the same time, even though each process is actually executing in slices.

1.1 What Is a "Process"?

Every running program is called a process. You can think of it as a "project team" with its own code (task list), its own memory data (project budget), queuing up for CPU attention.

1.2 Round-Robin Scheduling

To prevent any rogue software from monopolizing the CPU, the operating system slices CPU time into extremely small segments (about 10 milliseconds) and distributes them to each process in turn. Because the switching is so fast, it feels like "simultaneous execution."


2. Memory Management: Virtual Address Space

Having solved the problem of taking turns using the CPU, the next issue is memory space. Without management, if all software writes data directly to physical RAM, mutual overwriting stampedes are inevitable.

🧠 The operating system gives each program an illusion of memory
📱 Memory as the program sees it (virtual)
💬 Chat
1
2
3
4
🎮 Game
1
2
3
4
The operating system maps addresses ↓
💾 Real memory chips (physical)
1OS
2
3
4OS
5
6
7
8OS
💡 Principle: Each program thinks it owns a continuous block of memory on the left. In reality, the operating system spreads data across real memory on the right. The addresses a program sees are virtual, and the OS translates them.

2.1 Virtual Memory

The operating system tells each process a big lie: "Hey, you have exclusive use of all available memory on this entire computer. Use it freely!"

From the process's perspective, its memory space is always contiguous and clean. It peacefully writes data into it.

2.2 Page Table Mapping

In reality? The operating system secretly stuffs data into various fragmented gaps in real physical memory. This has two absolutely genius benefits:

  1. Absolute security: WeChat can only ever see its own space and can't tamper with other programs' data
  2. Fragment utilization: No matter how fragmented physical memory gets, the virtual space mapped to each process remains orderly

3. File Systems: Organizing Persistent Storage

If you buy a brand-new hard drive, it's essentially a barren expanse of storage units. If you want to save a photo, the hard drive will only ask: "Tell me which byte you want to store it at?"

📁 The file you see vs fragments on disk
📂 What you see (folder)
📁Photos
🖼️pet.jpg2.5MB
🖼️trip.png1.8MB
💾 Real disk storage (data blocks)
1
2
3Pet-1
4
5Trip-1
6Trip-2
7Pet-2
8
9
10
11Pet-3
12
💡 Principle: The file system splits a file into fragments stored in different disk blocks, then keeps a table of their locations. The tidy folder you see is a view built from that table.

3.1 What Does a File System Do?

  1. Partition the hard drive: Cut the hard drive into countless fixed-size blocks (typically 4KB)
  2. Maintain a ledger: Record which blocks are full and which are empty
  3. Translate paths: Convert D drive/Photos/Pet.jpg into "blocks 3, 7, and 11"

This is why renaming a file is instant (only the name in the ledger changes), while copying a file takes a long time (actual hard drive data blocks must be read and written).


4. Three-Way Coordination: The Complete Process of Launching a Program

We've now learned about the operating system's three major modules separately. Let's see how they work together when you double-click to open a program:

🚀 What is the computer doing after you double-click an icon?
1👆
You double-click the icon
The operating system receives a request to start the browser
2📋
Create a process
3🧠
Allocate memory
4📁
Load files
5▶️
Start running
🖱️
Clicking...

Whether you click a desktop icon or execute print("Hello World") in code, it all depends on this complex behind-the-scenes machinery. The reason we can surf the digital world so effortlessly is entirely because the underlying operating system bears the burden for us.


Further Reading

If you find the operating system's various "management tricks and deception tactics" fascinating, you can explore these advanced topics:

  • Processes and Threads: If a process is a project team, then "threads" are the employees doing the work within it
  • Concurrency and Locks: When two processes compete for the same resource simultaneously, how to prevent deadlocks
  • System Calls: The "service windows" the operating system provides to upper-layer applications