operating systems30 min

Processes

Independent programs running on your computer and how the OS manages them

0/9Not Started

Why This Matters

Right now, your computer is running dozens (maybe hundreds) of programs at the same time: a browser, a text editor, a music player, background services. Each running program is a process, and the operating system is responsible for managing all of them. Without processes, your computer could only run one program at a time, and a single crash would bring down the entire machine.

Understanding processes is the foundation of systems programming. When you start a web server, deploy a container, or debug a hanging application, you are working with processes. Every function you write runs inside a process, and every variable you declare lives in a process's memory. Knowing how the OS manages these running programs gives you the mental model to diagnose real-world problems like memory leaks, zombie processes, and application crashes.

Define Terms

Visual Model

New
Ready
Running
Terminated
WaitingBlocked
admit
dispatch
exit
I/O wait
I/O done
preempt

The full process at a glance. Click Start tour to walk through each step.

The process lifecycle: every running program transitions through these states.

Code Example

Code
// Node.js: Spawning a child process
const { exec, spawn } = require("child_process");

// exec: runs a command and buffers the output
exec("echo Hello from child process", (error, stdout) => {
  if (error) {
    console.log("Error:", error.message);
    return;
  }
  console.log("Output:", stdout.trim());
});

// spawn: streams output in real time
const child = spawn("ls", ["-la"]);

child.stdout.on("data", (data) => {
  console.log("Files:", data.toString());
});

child.on("close", (code) => {
  console.log("Child process exited with code:", code);
});

// Current process info
console.log("My PID:", process.pid);
console.log("Parent PID:", process.ppid);
console.log("Memory usage:", process.memoryUsage().heapUsed);

Interactive Experiment

Try these exercises:

  • Open a terminal and run ps aux (Linux/Mac) to see all running processes. How many are there?
  • Run top or htop to watch processes in real time. Which process uses the most CPU?
  • In Node.js, run process.pid to get your current process ID. Then check it with ps in another terminal.
  • Spawn a child process that runs a slow command. What happens if the parent process exits first?

Quick Quiz

Coding Challenge

Round-Robin Process Scheduler

Write a function called `roundRobin` that takes an array of process objects (each with `name` and `burstTime` properties) and a `timeQuantum` number. Simulate round-robin scheduling: give each process up to `timeQuantum` units of CPU time, then move to the next. Return an array of strings showing the execution log. Each log entry should be 'ProcessName ran for X units (Y remaining)' where X is the time it ran and Y is the remaining burst time. When a process finishes, Y should be 0.

Loading editor...

Real-World Usage

Processes are fundamental to everything in computing:

  • Web servers like Nginx spawn worker processes to handle requests in parallel.
  • Docker containers are isolated processes with their own filesystem and network namespace.
  • CI/CD pipelines spawn child processes to run tests, build artifacts, and deploy code.
  • Process managers like PM2 or systemd monitor processes, restart them on crash, and manage logs.
  • Debugging tools like strace and lsof attach to processes to inspect system calls and open files.

Connections