Understanding Processes: Basics, Forking, and Lifecycle in Operating Systems
This article explains what a process is, how it differs from a program, outlines its key characteristics, clarifies concurrency versus parallelism, describes how to create child processes, and covers orphan and zombie processes, termination methods, process groups, sessions, and race conditions.
Process
A process is an execution instance of a program on a data set, serving as the basic unit for resource allocation and scheduling in an operating system. It only runs after the system creates the necessary resources.
Difference Between Process and Program
A program is a static file containing ordered code stored on disk, while a process is the running instance of that program with allocated memory, variables, and resources such as heap and stack. When the program finishes, the process ends, but the program file remains.
Process Characteristics
Concurrency: multiple processes can progress simultaneously at a macro level.
Dynamic: processes are created, evolve, and terminate dynamically.
Independence: each process is the basic unit for system resource allocation.
Interaction: processes can communicate with each other.
Asynchrony: processes do not advance in lockstep.
Structure: each process has a control block (PCB).
Parallelism: true parallel execution requires multiple CPUs or processors.
Concurrency vs. Parallelism
Concurrency is the macro‑level perception that processes advance together, achieved by the CPU time‑slice scheduling mechanism; the eye cannot see the rapid switches. Parallelism means multiple processes truly execute at the same instant, which only occurs on multi‑CPU systems.
Creating Multiple Processes
Processes can be created by the operating system or by a parent process. A child process inherits almost all resources from its parent, and child processes can further create their own children, forming a process family.
Orphan Process
An orphan process is one whose parent has terminated before it; the init process (PID 1) adopts such a process.
Zombie Process
A zombie process occurs when a child terminates but its parent has not yet performed a wait, leaving the kernel retain minimal information about the child. The zombie occupies resources until the parent reaps it.
Process Termination Methods
Returning from the main function.
Calling exit().
Calling _exit() or _Exit().
The last thread returning from its start routine.
The last thread calling pthread_exit().
Calling abort() (generates SIGABRT).
Receiving a terminating signal.
The last thread responding to a cancellation request.
Process Group
Every process belongs to a process group, which is a collection of one or more related processes that can receive signals from the same terminal. Each group has a unique group ID, and the process whose PID equals the group ID is the group leader.
Session
A session is a collection of one or more process groups.
Race Condition
A race condition arises when multiple processes access shared data and the final result depends on the order of execution, which is determined by the kernel scheduler and system load. Using wait / waitpid can serialize execution but defeats the purpose of concurrency. Instead, synchronization mechanisms such as signals or inter‑process communication (IPC) should be employed to avoid race conditions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
