Ensiklopedia VibeKoding: Operating Systems Principles: Processes, Memory, and File Systems.Ensiklopedia VibeKoding: Operating Systems Principles: Processes, Memory, and File Systems.
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.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?What will you learn from this article?
After completing this chapter, you will gain:After completing this chapter, you will gain:
| Chapter | Content | Core Concepts |
|---|---|---|
| Chapter 1 | Process Management | CPU time-division multiplexing, round-robin scheduling |
| Chapter 2 | Memory Management | Virtual memory, paging mechanism |
| Chapter 3 | File Systems | File organization, directory structure |
------
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).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):If you don't hire a factory manager (operating system):
To solve these three nightmares, the operating system deploys its three magic weapons: process management, memory management, and file systems.To solve these three nightmares, the operating system deploys its three magic weapons: process management, memory management, and file systems.
------
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?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 answer: It doesn't do them simultaneously. Instead, the operating system performs frantic "time management."
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.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.
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."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."
------
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.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 tells each process a big lie: "Hey, you have exclusive use of all available memory on this entire computer. Use it freely!"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.From the process's perspective, its memory space is always contiguous and clean. It peacefully writes data into it.
In reality? The operating system secretly stuffs data into various fragmented gaps in real physical memory. This has two absolutely genius benefits:In reality? The operating system secretly stuffs data into various fragmented gaps in real physical memory. This has two absolutely genius benefits:
------
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?"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?"
D drive/Photos/Pet.jpg into "blocks 3, 7, and 11"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).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).
------
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: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:
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.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.
------
If you find the operating system's various "management tricks and deception tactics" fascinating, you can explore these advanced topics:If you find the operating system's various "management tricks and deception tactics" fascinating, you can explore these advanced topics: