Bootstrap Process Explained


Bootstrap Process Explained

Corey
We talked last week about the bootstrap program that runs when you start a computer. It checks hardware, then looks for an operating system on a hard disk or USB and hands control to it. But here's the clever bit: that bootstrap can be extended to a boot loader like GRUB, which gives you a menu to choose between multiple operating systems — Windows, Linux, whatever you've installed.

Hope
And GRUB isn't just for Linux, right? It works with anything. So if you dual-boot, you can pick which OS to load. That's a nice way to handle multi-boot systems.

Corey
Exactly. Now, an operating system provides five core services: file system management, I/O handling, user interface, memory management, and process management. We've touched on some of these before, but the key is that in a monolithic OS like older versions of Windows, all these services are baked into one big kernel. A layered or modular OS, like modern Linux, loads only what's needed, which is more flexible but a bit slower due to the communication between layers.

Hope
And that ties into system calls. A system call is how a program requests a service from the OS — like creating a file or sending data over the network. It's not an interrupt; an interrupt is a hardware signal. System calls are part of the API the OS exposes.

Corey
Right. And system programs are utilities that come with the OS to help manage the system — things like the command prompt's DIR command, Check Disk, or Task Manager. They aren't for getting work done directly; they help you understand and control what's happening.

Hope
The command interpreter, or shell, is a special system program that reads your commands and starts processes. For example, in Unix you can type a command, and the shell forks a child process and executes it. We even saw that in the LMC, where you load a program and run it step by step.

Corey
And that leads us to processes. A process is a program in execution. It has a text section (code), data (global variables), a stack for short-term data, and a heap for dynamic memory. The stack and heap grow toward each other to maximize memory use. A process goes through states: new, ready, running, waiting, and terminated. When a new process is created, it enters the ready queue. When the CPU is free, the scheduler dispatches it to run.

Hope
But processes don't run forever. They can be interrupted for I/O — like waiting for a keypress — and then they go into a waiting queue. When the I/O completes, they return to ready. Or they can be preempted because their time slice ran out, and they go back to ready. And if they finish or crash, they terminate and release resources.

Corey
That process state diagram is fundamental. And to switch between processes, the OS performs a context switch: it saves the current process's state into its Process Control Block — program counter, registers, memory info — and loads the next process's PCB. This takes time, so there's overhead. Hardware can help by having multiple register sets for faster switching.

Hope
Context switching lets us time-share the CPU, making it seem like many processes run at once. But if you push it too far, the system spends more time switching than doing actual work — you see the system slow down.

Corey
And then we have threads, which are lightweight processes within a process. Multiple threads can run on different cores or CPUs, achieving true parallelism. For example, a web browser can have one thread for the UI, one for rendering, and one for network requests — all working simultaneously.

Hope
Threads will get their own week later. Now, about schedulers: we have a short-term scheduler that decides which ready process gets the CPU next, operating in milliseconds. Then a long-term scheduler brings new jobs into the ready queue — like a scheduled backup at 6 PM. Some systems also have a medium-term scheduler that swaps out idle processes to disk (swapping) to free up memory.

Corey
A good scheduler balances CPU-bound processes (heavy computation) with I/O-bound ones (waiting for input). That mix keeps the system efficient. The scheduler can also prioritize processes, giving some more CPU time than others.

Hope
Processes can be created by forking — a parent spawns a child. The child might execute a different program. Termination can cascade: if a parent terminates, its children must be terminated too, or they become orphans. Or you can have zombies if a child terminates but the parent hasn't waited for its exit status.

Corey
And processes often need to communicate. For processes on different machines, we use sockets — an IP address gets data to the computer, and a port number directs it to the right service (like port 80 for web traffic). For processes on the same machine, we can use pipes: unidirectional or bidirectional, even named pipes for multiple connections.

Hope
Interprocess communication also has to handle differences in data representation. If one system uses big-endian byte order and another uses little-endian, the numbers won't match without conversion. Middleware like Microsoft's IDL can help systems from different vendors talk to each other.

Corey
So that's a whirlwind tour of processes, scheduling, and communication. It's all about balance: managing resources so that the user gets a responsive system while the OS does its work efficiently. We'll dive deeper into scheduling and threads next week.

Ask anything
We've read this whole study set, so questions about it get the best answers.