In the world of computers, we often use the terms “program” and “process” interchangeably, but they’re actually very different. Think of a program as a recipe book sitting on your kitchen counter. It’s a set of instructions, but it’s not doing anything on its own. It’s a passive entity, just a file stored on your hard drive.

A process, on the other hand, is the recipe in action. It’s you, the cook, actively following the instructions: getting ingredients, mixing them, and baking the cake. A process is an active, dynamic entity that is running and using system resources like the CPU and memory. When you double-click an application icon, like a web browser or a word processor, you’re creating a new process.

Anatomy of a Process

When a program becomes a process, the operating system (OS) loads it into memory and sets up a data structure called a Process Control Block (PCB). This is like the cook’s personal to-do list and ingredient list for the recipe. The PCB contains everything the OS needs to manage and control the process. This includes:

  • Process State: The current state of the process (e.g., running, waiting).
  • Process ID (PID): A unique number that identifies the process.
  • Program Counter: This is a crucial piece of information. It’s like a bookmark in your recipe book, telling the cook exactly which instruction to do next. It points to the next instruction to be executed.
  • CPU Registers: These are small, fast storage locations in the CPU that hold temporary data for the process. They need to be saved and restored when the OS switches between processes.
  • Memory Management Information: Details about the memory allocated to the process, including where the code, data, and stack are located.

The Process Lifecycle: States of Being

A process doesn’t just exist; it moves through different states during its lifetime. Imagine the process as an actor on a stage. The main states are:

  • New: The process is being created. It’s like the actor just walking onto the set, getting ready for the scene.
  • Ready: The process is ready to run but is waiting for its turn on the CPU. The actor is in the wings, waiting for their cue. There can be many “ready” processes waiting in a queue.
  • Running: The process is actively executing instructions on the CPU. This is the actor on stage, delivering their lines. On a single-core CPU, only one process can be in the “running” state at any given moment.
  • Waiting (or Blocked): The process has temporarily stopped executing because it’s waiting for an event to happen. The actor is waiting for another actor to finish their line or for a prop to be brought on stage. Common events include waiting for user input (like a mouse click or a keystroke) or for an I/O operation (like reading a file from the disk).
  • Terminated: The process has finished its job and is being removed from memory. The actor has taken their final bow and is leaving the stage. The OS reclaims all the resources that were used by the process.

Multitasking and CPU Scheduling

Modern operating systems are masters of multitasking. They create the illusion that multiple programs are running at the same time, even on a single CPU. They do this through a process called CPU scheduling. The OS has a special program called a scheduler that acts as a traffic cop, deciding which “ready” process gets to move to the “running” state and for how long.

There are different scheduling algorithms that the scheduler uses. A simple one is First-Come, First-Served (FCFS), where processes are executed in the order they arrive, like a queue at a grocery store. A more common and fairer approach is Round Robin, where each process is given a small, fixed amount of CPU time (called a “time slice”). If the process doesn’t finish within that time, it’s put back at the end of the ready queue, giving other processes a chance to run. This rapid switching between processes, known as a context switch, is so fast that it seems like everything is happening simultaneously.

In essence, the operating system’s management of processes is what makes a computer feel responsive and allows us to do many things at once, from browsing the web to listening to music and editing a document, all without a hitch.


Discover more from Shafaat Ali Education

Subscribe to get the latest posts sent to your email.

Leave a comment

Recent posts

apple books

Buy my eBooks on Apple Books. Thanks! Shafaat Ali, Apple Books

Discover more from Shafaat Ali Education

Subscribe now to keep reading and get access to the full archive.

Continue reading