Chapter 1: What Is an Operating System? Your Computer’s Super Helper
Imagine you’re in a classroom full of 20 kids, all wanting to use the whiteboard to draw, borrow colored pencils from the supply closet, and turn in their homework to be graded. If there’s no one in charge of organizing all of this, chaos would break out in seconds: two kids would fight over the whiteboard, crayons would go missing, and homework would get mixed up so badly no one would know who got an A and who forgot to do their assignment. This in-charge, super-organized classroom helper is exactly what an operating system (OS for short) is for your computer. For this book, we’re going to name our OS helper Ollie, to make it easier to talk about all the cool things it does behind the scenes.
Ollie doesn’t just sit around waiting for you to ask for things. It works 24/7 to make sure every part of your computer gets a fair turn to be used, that no program messes up another program’s work, and that all your files, photos, and games stay safe and easy to find. Without Ollie, even the simplest task—like opening a drawing app to doodle a cat—would require you to write hundreds of lines of code just to tell the computer’s brain (the CPU) how to turn on the screen, how to listen when you tap the screen, and how to save your drawing when you’re done. Ollie takes care of all that boring, complicated work so app developers can focus on making fun, useful programs for you to use, and you can focus on playing, learning, and creating without worrying about the messy details of how the computer works.
<!-- 纸书格式标记:本节为第1章核心概念引入,使用 classroom helper 类比降低儿童理解门槛 --> <!-- 电子版格式标记:包含侧边栏小提示,点击可跳转至Linux官网 --> <!-- Markdown格式标记:结构化引入,标签为操作系统基础、儿童类比 -->
Let’s Meet Ollie’s Three Most Important Jobs
Ollie has thousands of little tasks to do every second, but all of them fit into three big, easy-to-remember categories that we’ll explore for the rest of this book. We’ll use our classroom analogy to make each one make sense: 1. Process Management (Managing All the Tasks Everyone Is Doing) Think of every app, game, or task running on your computer as a kid in the classroom with a job to do. The kid drawing a poster is one task (we call this a *process* in computer terms), the kid solving a math worksheet is another process, and the kid listening to music during free time is a third process. Ollie’s first big job is to make sure all these processes get a fair turn to use the classroom’s limited resources—like the whiteboard, the calculator, or the speakers. If the kid drawing the poster needs the whiteboard for 5 minutes, Ollie will give it to them, then switch to let the math kid use the calculator for 2 minutes, then let the music kid use the speakers for the rest of free time. If two kids start fighting over the same pencil case, Ollie will step in to separate them and find a solution so no one gets left out. This is exactly what process management does for your computer: it makes sure the CPU (your computer’s “thinking brain”) splits its time fairly between all running programs, stops programs from fighting over resources, and even steps in to fix problems if a program freezes or crashes. 2. Memory Management (Organizing the Temporary Storage Desks) Every kid needs a desk to put their pencils, eraser, and half-finished worksheet on while they work. If the desk is too small, they can’t fit all their supplies; if it’s too big, they’re wasting space that another kid could use. Ollie’s second big job is to manage all the desks (we call this *memory* or RAM in computer terms) in the classroom. Ollie gives each process (each kid’s task) exactly as much desk space as they need, no more and no less. It also puts up little dividers between desks so no kid can accidentally (or on purpose) erase another kid’s worksheet. If the classroom runs out of desks, Ollie will move the supplies from kids who are taking a break (like the kid who finished their math worksheet and is waiting for the teacher to grade it) to the big storage closet in the back (the hard drive or SSD on your computer) until they need those supplies again. This is called *virtual memory*, and it lets your computer run way more programs than it would normally have space for. 3. File System (Organizing the Long-Term Storage Closets) When a kid finishes a poster or a worksheet, they need to put it somewhere safe to save for later, so it doesn’t get lost or crumpled. Ollie’s third big job is to manage all the storage closets, file folders, and labeled bins (we call this the *file system* in computer terms) where all your files, photos, games, and homework are saved long-term, even when you turn the computer off. When you save a drawing you made, Ollie will stick a label on it with your name, the date, and what it is, then put it in the right folder in the storage closet. When you want to find that drawing later, you just tell Ollie “I want my cat drawing from last week” and it will pull it out for you in seconds. Ollie also locks certain folders so only you can open them—like your private diary folder that no one else is allowed to read, or your homework folder that only your parents and teacher can check.
> 💡 电子版侧边栏提示:你平时用的手机、平板、游戏机里都有Ollie一样的OS在工作哦!比如你的安卓手机里的OS就是基于Linux内核做的,和你后面要看的Linux内核是同一个“规则本”改出来的。
<!-- 纸书格式标记:动手时间框 --> > 📌 动手时间:找一找你家里有没有跑Linux的设备?比如智能电视、路由器、树莓派开发板,甚至有些玩具机器人里都有Linux OS哦!看看你能不能找到它们的系统信息。
Now that you know what Ollie does, let’s talk about the most important part of Ollie: its core rulebook, called the Linux kernel. You might have heard of Linux before—it’s the OS that runs on almost all the world’s cloud servers (the big computers that power the internet), all Android phones, most smart watches, and even the Mars rovers NASA uses to explore the red planet! But what exactly is the Linux kernel?
What Is the Linux Kernel, Anyway?
Remember how we said Ollie is the OS helper? Well, the OS you see on your screen—the desktop, the icons, the start menu, the app store—is just the friendly face Ollie shows you. The *kernel* is the tiny, super-smart brain inside Ollie’s head that holds all the rules for how to do the three jobs we talked about: process management, memory management, and file system management. Every single thing your computer does, from turning on the screen to running your favorite game, goes through the kernel.
The coolest thing about the Linux kernel is that it’s open source. That means the entire rulebook is available for anyone in the world to read, use, and even improve for free! It’s like if your school published Ollie’s entire rulebook online, so any student, teacher, or even kid from another school could read it, find ways to make Ollie work better, and send those ideas to the class to vote on. If enough people think the idea is good, it gets added to the official rulebook for everyone to use.
You don’t need any special software to read the Linux kernel’s rulebook. Just open your web browser and go to [kernel.org](https://kernel.org) (that’s the official public library for the Linux kernel rulebook). You’ll see links to download the full source code for the latest stable version of the kernel, which as of 2024 is the 6.x series. You can even download it to your own computer and open the files with a simple text editor to read the rules yourself! Don’t worry if the code looks weird at first—we’ll walk through simple, easy-to-understand parts of it together later in this book.
<!-- Mermaid 分层图:展示OS在用户和硬件之间的位置,符合三件套要求 --> ```mermaid graph TD A[👩💻 你(小探险家)] --> B[🎮 你的App/游戏/作业工具<br/>(用户程序/进程)] B -->|📝 递小纸条(系统调用)| C[🧠 Ollie的办公室(Linux内核)] C -->|🔧 执行操作| D[🖥️ 电脑硬件<br/>(CPU/内存/硬盘/白板/抽屉)] C -->|✅ 返回结果| B ``` *Figure 1-1: How the OS sits between you, your apps, and the computer hardware. Just like you can’t grab the whiteboard directly without asking Ollie, your apps can’t touch the hardware directly without asking the kernel first!*
Why Can’t Apps Just Talk to the Hardware Directly?
You might be wondering: if Ol