100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

What Is a Process?

Learn what a process is, how it differs from a program, and how the OS creates and manages processes.

Process ManagementBeginner8 min readJul 8, 2026
Analogies

Introduction

A program is a passive entity — an executable file sitting on disk containing instructions and static data. A process is an active entity: a program in execution, loaded into memory, with its own address space, current activity, and set of resources allocated by the operating system. Every time you run a program, the OS creates a new process to represent that running instance, even if you run the same program twice simultaneously.

🏏

Cricket analogy: A match strategy written in a coach's notebook is like a program, passive until execution; the actual live match being played on the field, with a real scoreboard and live state, is the process, an active instance of that plan.

Explanation

A process consists of several logical components: the text segment (compiled code), a data segment (global and static variables), a heap (dynamically allocated memory), and a stack (function call frames, local variables, return addresses). The OS tracks each process using a data structure called the Process Control Block (PCB), which stores the process ID (PID), CPU register values, memory pointers, open file descriptors, and scheduling information. On POSIX systems, a new process is created with the fork() system call, which duplicates the calling process; the child can then replace its memory image with a new program using an exec() family call such as execvp().

🏏

Cricket analogy: A player's PCB is like a scorecard entry tracking their stats, form, and current over count; fork() is like a twelfth man being cloned into a substitute who then dons a different kit (exec) to play a completely different role.

Example

c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void) {
    pid_t pid = fork();

    if (pid < 0) {
        perror("fork failed");
        exit(EXIT_FAILURE);
    } else if (pid == 0) {
        /* Child process */
        printf("Child: my PID is %d, parent PID is %d\n",
               getpid(), getppid());
        execlp("/bin/echo", "echo", "Hello from exec'd process", NULL);
        /* execlp only returns on failure */
        perror("exec failed");
        exit(EXIT_FAILURE);
    } else {
        /* Parent process */
        int status;
        printf("Parent: created child with PID %d\n", pid);
        waitpid(pid, &status, 0);
        printf("Parent: child exited with status %d\n",
               WEXITSTATUS(status));
    }

    return 0;
}

Output

Running this program prints the parent's message that it created a child, then the child prints its own PID and its parent's PID, then the child replaces its own image with /bin/echo which prints 'Hello from exec'd process', and finally the parent prints the exit status it collected via waitpid(). The fork() call returns twice — once in the parent (with the child's PID) and once in the child (with 0) — because after fork() both processes exist independently with separate address spaces, even though the child's memory starts as a copy of the parent's.

🏏

Cricket analogy: The parent announcing 'new batsman sent in' while the debutant walks out and later plays their own innings, with the captain later confirming the outcome, mirrors fork() returning twice, once to the parent with the child's ID and once to the child with zero.

Key Takeaways

  • A process is a program in execution; a program on disk is a passive entity, a process is active.
  • Each process has its own address space: text, data, heap, and stack segments.
  • The OS represents every process with a Process Control Block (PCB).
  • fork() creates a new child process by duplicating the caller; exec() replaces a process's memory image with a new program.
  • Two processes running the same program are still distinct processes with distinct PIDs and memory.

Practice what you learned

Was this page helpful?

Topics covered

#OperatingSystemsStudyNotes#OperatingSystems#WhatIsAProcess#Process#Explanation#Example#Output#StudyNotes#SkillVeris#ExamPrep