Computers: How Does it Work?
Computers: How Does it Work?
First off, let's get this mental image out of the way: there aren't actually tiny little elves inside your laptop, pedaling their hearts out, grateful for a tiny break whenever you turn and take off your headphones to answer someone's questions. No one's in there placing bets on when you’ll step away from the monitor for a few moments so that they can cat nap or grab a snack.
This shouldn't come as a surprise if you noticed that becoming a member of the Geek Squad or the Genius Bar doesn't require CPR certification for those tiny magicians powering the information revolution. Nope, there aren't any
- elves
- techno-fairies
- Steampunk-style talking mice
powering your computer—or any other electronic device, for that matter.
Deep breath. Let's talk about how it actually works.
Turning the Computer On
Every time you turn a computer on, the CPU (Central Processing Unit) springs into action first, followed by the other hardware. This process of turning on all the hardware is called booting up. The first thing to turn on? The Basic Input Output System (BIOS), of course. BIOS is a firmware component that comes pre-installed on the motherboard.
Side note: when we say firmware, we mean something between hardware and software that acts like permanent software programmed into a ROM (Read-Only Memory). Okay, back to your regularly-scheduled explanation.
The first thing BIOS does is initiate the Power-On-Self-Test (POST). POST acts like roll call, making sure all of the expected hardware components are present and working correctly. If the POST is successful, BIOS looks for the CMOS chip (which holds the system clock and additional system settings) in the first 64 bytes of RAM (Random Access Memory).
Next, BIOS figures out whether the computer's running a cold boot (starting up from having been powered off) or a warm boot (re-starting). If it's running a warm boot, some of the POST steps can be skipped because…they were just on.
During the boot-up process, BIOS also does a read/write check of every RAM memory address. If you're watching the start-up screen, you can usually see this step as an infinite scroll of white text being added to the screen. The boot-up's job is to make sure that all the hardware components are talking to each other. Once it checks those connections, it's going to load all the internal software programs like
- interrupt handlers
- device drivers
- the operating system
from the hard disk into RAM. Then the computer can start thinking about interacting with you.
Computer Go Time
Once the computer’s booted up and ready to go, that's your cue to tell it what to do by entering a command or clicking an icon. If you click on an icon, you're telling the computer what program you want to run. It sounds like a job for a Keebler elf, and…it could be, but most computers just use technology instead. Fewer labor laws that way.
When you click the icon, the operating system, stepping in as secretary, schedules the software for an execution appointment in the CPU. Sometimes that's enough, but usually the software prompts the user to give some more information before it continues to run and give meaningful output.
Say you're getting ready to leave your house. If you clicked on a weather app to figure out whether to wear flip-flops or a down coat, the app might need to ask you for your location so that the weather it reports is, you know…accurate. While your PC’s waiting for you to send it that address or ZIP/postal code for your location, the operating system sent in the interrupt handlers to tell the CPU to hold off until the weather app has all the input it needs. Around this point the operating system looks around to see if any other app needs some one-on-one time with the CPU. Maybe that music app playing your get-pumped-for-going-outside playlist.
Since the CPU can only do one thing at a time, the operating system wants to make sure it's always doing something so that it can do as much as possible. Meanwhile the operating system juggles requests from all the different apps that look like they're all running at the same time (even though the CPU jumps between them constantly).
To trick you into thinking that all the apps you're running are going at the same time, the operating system uses a Process Control Block (PCB, which is just a small data structure). In the PCB, the OS stores the address of where it left off in the weather app, along with the addresses pointing to any other information the CPU needs to continue running the app once you input your location. All of this swapping back and forth between applications and input/output requests is handled by the operating system. Neither you nor the elves need to lift a finger to get this work done.
But wait, there's more.
As it manages the CPU's time, the operating system also handles all the memory management. Each active application needs to be stored somewhere in memory that won't end up trying to overwrite the memory locations of other active applications—or their data.
Wait, what?
If, in the process of saving your location, the weather app overwrote part of your favorite song from the get-pumped-for-going-outside playlist (essentially corrupting it), you'd probably get pretty annoyed. Sure, the weather app would work just fine, but now "The Outside World isn't That Scary (I Promise)," can never be played again. Womp, womp.
To avoid destroying the greatest hit from the mid-2000s in the Everyday Positivity Rock genre, the operating system keeps track of the starting location and size of every active application. It also keeps track of both the location and size of data being used by those active applications. Since it knows the location and size of the apps and their date, the operating system can avoid overwriting information.
Most of the time, anyway.
But back to the flip flops versus down coat debate going on in your weather app. Once the location's in, the operating system goes back to the app and gets it prepped for the CPU again. The weather app software that's loaded in the computer will tell the operating system where to go to get the current forecast for your location. It isn't actually that simple, though.
Connecting to the Internet
Since your computer doesn’t have the current weather information for every location in the world, it needs to go somewhere else to get it. At this point, that "somewhere else" is probably the internet. Just a hunch. The computer needs to use a router to find another computer with the current weather information for your location.
Every computer connected to the internet has a unique Internet Protocol (IP) address. If your weather app's any good, its code will tell the computer which IP address it needs to go to in order to grab the weather data it needs. Your operating system already knows what your computer’s own IP address is. With its own address and the address the app gives, it manages the communication between the two addresses the same way that it handles communications between two memory addresses in the same computer.
The only difference is that the communication gets passed through a network of cables.
Hint, hint: that's the internet.
Once the weather app gets the data it needs about current weather conditions from that other computer, the software formats that information into something that’s nice and readable. With everything formatted, it's going to ask the operating system to show results on an output device like your cell phone screen or a computer monitor. When you see the weather forecast for your location, you're looking the weather app's generated output—plus a cool graphic or two.
If you decide to print the forecast and post it on the refrigerator so that you can make weather-specific plans (choosing to ignore the fact that those predictions will only be right about 50% of the time), you'd use a print command, telling the operating system to take the exact output you're looking at and send it over to a printer.
Once you do this, the operating system may ask you many questions about how many copies you want and whether you want that sun ClipArt in all its color glory or just a drab gray scale. Or maybe you'll want to email that same weather report to a relative several states away (you know, those less computer-literate ones who don’t know how to download their own weather app) so they don't need to worry about your house getting hit by a tornado or something.
Don't get us wrong: they're totally going to worry about you all the same, but it's the thought that counts.
When you activate your email software (probably by clicking on the icon), the operating system is going to do the same exact thing it did before: load the email software into RAM and allocate some CPU time to your email app. At some point after it starts to run, an interrupt handler will send a request to the keyboard asking you, the user, for an email address, to successfully send the weather report as output Nana Booboo.
Turning off the PC
When you turn your computer off, you have to be careful. Vey careful.
Sure, you press and hold the power button until you hear the fan shutter to a stop and the screen go black, but ad the same time you could accidentally corrupt the data if you don’t let the operating system run all its steps for shutting down. If you go through the shut-down option from the menu on the screen, the operating system gets a chance to keep chunks of data and programs from laying around, cluttering things up and causing the memory to be fragmented.
The operating system goes through a series of checks to keep the computer running efficiently and without errors. It goes something like this:
- The OS checks to see if multiple users are logged in and if they are, asks the user (that's you) if they still want to shut down. If it shuts down without asking and someone else is logged in, they'll lose any data in the RAM that they didn't save to the long-term memory, which isn't fun.
- Next, the operating system checks all the open applications for unsaved data (the stuff in the short-term memory, but not the long-term memory), asks the user if they want to save it, and then closes each program.
- It logs all the users off the PC…but safely.
- Then the power gets shut off, meaning all the transistors in the short-term memory get reset. If you had any data there that you didn't save, it's now gone. Sorry.
Using the shut-down option instead of pressing and holding the power button like taking a multivitamin every day: it won't hurt you and helps prevent problems down the road.