What is a Process?
You've probably opened multiple apps on your phone or computer at the same time. Maybe you're browsing the web, listening to music, and have a chat app running. Each of those is a process โ a program that's currently executing.
Here's the key distinction: a program is a static file sitting on your disk. It's like a recipe written on paper โ it has instructions, but nothing is actually happening. A process is that recipe being followed in a kitchen โ ingredients are being mixed, the oven is on, and food is being prepared. The program is passive; the process is active.
When you double-click an icon to open an application, the operating system creates a new process, allocates memory for it, loads the program code, and starts executing it. That process now has its own life cycle โ it can run, wait, be paused, and eventually terminate.
What's Inside a Process?
Every process has several components that the OS needs to track:
- Process ID (PID) โ A unique number assigned by the OS to identify the process. It's like a social security number for your program.
- Program Counter โ Keeps track of which instruction the process is currently executing. Think of it as a bookmark in the recipe.
- Memory โ The code, data, and variables the process needs. This includes the program's instructions, global variables, and dynamically allocated memory.
- Open Files โ Any files the process has open for reading or writing.
- CPU Registers โ Temporary values stored in the processor that belong to this process.
- Process State โ Whether the process is running, waiting, ready, or terminated.
All of this information is bundled together in a data structure called the Process Control Block (PCB), which we'll explore in detail in the next lesson.
Process vs. Program
Let's make this crystal clear with an analogy. Imagine a musical play:
- The script is the program โ it contains all the instructions, dialogues, and stage directions.
- A performance of the play is a process โ actors are on stage, lines are being delivered, and the story is unfolding in real time.
You can have multiple performances of the same play running at the same time in different theaters (multiple processes running the same program). Each performance has its own actors, audience, and state โ but they're all following the same script.
This is why you can have five instances of Chrome open simultaneously. Each is a separate process, but they all use the same program code stored on your disk.
Why Processes Matter
Processes are the fundamental unit of work in an operating system. The OS uses processes to:
- Isolate programs โ If one process crashes, it doesn't bring down others. Your browser crashing shouldn't close your music player.
- Share resources โ The CPU, memory, and I/O devices are shared among all running processes.
- Enable concurrency โ Multiple tasks can appear to run simultaneously, even on a single-core CPU.
- Manage security โ Each process has its own memory space, preventing one program from reading or modifying another's data.
Without processes, a single bug in one program could corrupt the entire system. Processes are the walls that keep programs from interfering with each other.