Transcript
HostWe use these machines every day, but I think most of us have a picture of what's happening under the hood that's just wrong. You see your music playing while you're typing an email and maybe downloading a big file, and it feels like the computer is just this great multitasker doing twenty things at once.
GuestIt really looks that way, but if you could slow down time by a million times, you would see a totally different show. It's more like a single person on a stage frantically juggling dozens of balls, but they're moving so fast that it looks like all the balls are just hanging in the air. Your computer brain, the processor, can really only do one tiny step of one task at a time. The operating system is the one running the show. It has a part called the scheduler that acts like a very strict boss with a stopwatch. It uses a way of working called preemptive multitasking. Basically, it gives one app a tiny sliver of time, maybe just a few thousandths of a second, then it yells time is up, freezes that app, and shoves the next one in. It does this over and over so fast that our human eyes can't see the gaps.
HostWait, if it's freezing them and swapping them out that fast, how does it remember where it was? If I'm mid-sentence in an email and the boss swaps me out, does it not lose my spot?
GuestThat's the big trick. The operating system does something called context switching. Right before it pauses an app, it saves a perfect snapshot of every tiny bit of data the app was using in the processor at that moment. Then it clears the desk, puts the next app's data down, and lets it run. When it's time for the first app to come back, it loads that snapshot back in. It's so smooth that the app doesn't even know it was ever paused. And it's a good thing, too, because if one app gets stuck or tries to hog all the time, the operating system can just force it to stop so the whole computer doesn't lock up.
HostSo it manages time by being a strict boss. But what about space? I have all these files and apps open, and they're all sitting in the memory. How do they not trip over each other or read each other's mail?
GuestThis is where the operating system acts like a very clever librarian. See, if every app could just grab any spot in the computer's memory, they would eventually try to write over each other. It would be a total mess. To stop that, the system uses something called virtual memory. It basically tells a lie to every app. It gives each program its own private sandbox, which is called a virtual address space, and it tells the app that it has the entire computer memory all to itself.
HostBut it does not.
GuestNot even close. Behind the scenes, the operating system is mapping those fake private spaces to the real, physical spots in your memory sticks. The app thinks it's sitting in spot number one, but the system has actually tucked it away in spot five thousand. If a program tries to reach outside its own assigned box to peek at another app's data, the system catches it. It calls that a segmentation fault and just kills the program on the spot. It keeps your other data safe from being messed with or read by a program that shouldn't be there.
HostThat feels a bit like a babysitter. But I have had plenty of times where a website freezes up, and the whole browser tab dies, but the rest of my computer stays fine. Why does the whole thing not go down with the ship?
GuestThat's because of how the system draws a hard line between two separate worlds. Most of the stuff you use, like your browser or a game, lives in what's called user mode. In that mode, the apps are strictly forbidden from touching the actual hardware like the screen or the disk directly. If they want to do anything special, like save a file or send data over the internet, they have to make a formal request called a system call to the kernel. The kernel is the inner core of the operating system that has total control over the silicon. It looks at the request, checks if the app is allowed to do it, and then does the task for them. This hard line is the reason a messy website can freeze your browser without making your screen go black or your hard drive stop spinning.
HostI guess I never thought about how much work goes into just keeping things apart. But there are so many different types of gear out there. How does a piece of software know how to talk to a thousand different types of printers or mice?
GuestThat might be the most overlooked job the system has. It provides a common language. Think about it: every mouse or keyboard works a little bit differently. If a developer had to write special code for every single model of mouse ever made, they would never finish anything. Instead, the operating system gives them a standard set of tools, or APIs. The app just says save this file, and the system handles the gritty details of talking to that specific hardware using a piece of software called a device driver. It handles the literal electrical signals and the magnetic writes to the disk.
HostThis translator role seems to be the only thing keeping the whole industry from collapsing under its own weight.
GuestIt really is. It hides all that messy hardware variety so that the same version of an app can run on millions of different computers without the people who built it having to worry about what brand of hard drive you bought.
HostThat hyperactive performer is doing a lot of heavy lifting behind the scenes just to keep the show running smoothly for us.
Made with Wander
A world of curiosity you can listen to. Explore endless questions, or ask your own.
Get the app