The journey begins when a user interaction (like double-clicking an icon or typing a command) triggers a request to the kernel—the core of the OS. The program, which is a static file known as an executable (e.g., an ELF file or a PE file), is merely a sequence of instructions and data until the OS acts upon it.
Process Instantiation and Loading
- System Call: The shell or graphical environment issues a system call (like
execveon Linux orCreateProcesson Windows) to the OS kernel, requesting the execution of the program file. - Process Creation: The kernel creates a new administrative structure called the Process Control Block (PCB). The PCB is the process’s identity card, containing its unique Process ID (PID), its current state (ready, running, waiting), security permissions, and the values of its CPU registers.
- Virtual Memory Allocation: The OS allocates a virtual address space for the new process. This address space is a conceptual map that the program believes is its own contiguous memory, isolating it from other processes and protecting the kernel. The kernel then begins loading sections of the executable file from the slow disk storage into the faster Random Access Memory (RAM).
- Memory Segmentation: The program’s code and data are mapped into this virtual space in distinct segments:
- The Text Segment holds the actual machine code instructions (read-only).
- The Data Segment holds global and static variables.
- The Heap is reserved for dynamic memory allocated during runtime.
- The Stack is used to manage function calls, local variables, and return addresses (Last-In, First-Out).
Linking and Initialization
Before execution can begin, two final setup steps are performed:
- Dynamic Linking: Most modern programs rely on shared libraries (e.g.,
.dllor.sofiles) for common functions (like input/output, networking, or GUI drawing). The dynamic linker loads these necessary libraries into the process’s virtual address space and resolves all the external function calls, connecting the program to the system’s resources. - Entry Point: The OS initializes a special CPU register, the Program Counter (PC), to the memory address of the program’s first instruction (the “entry point,” often the
mainfunction).
Execution: The CPU’s Instruction Cycle
Once the process is loaded and initialized, the CPU Scheduler selects it to run on a processor core. The CPU then begins its fundamental work cycle, repeated billions of times per second:
- Fetch: The Control Unit uses the address stored in the Program Counter to retrieve the next machine code instruction from memory (RAM or the CPU’s cache).
- Decode: The instruction is translated into internal commands that the CPU’s components can understand and execute.
- Execute: The Arithmetic Logic Unit (ALU) or other specialized hardware performs the specified operation (e.g., addition, data movement, comparison, branching). The results are often temporarily stored in high-speed Registers within the CPU core.
- Write-Back: The final results are written back to a register or memory location.
Context Switching and I/O
The process does not run continuously. The OS ensures fairness and responsiveness through preemptive multitasking:
- Time Slicing: A hardware timer periodically generates an interrupt, forcing the CPU to pause the currently running process. The OS saves the complete state of the process (all register values) into its PCB, selects the next process from the queue, loads its saved state into the registers, and resumes its execution. This rapid context switching creates the illusion of simultaneous execution for multiple programs.
- System Calls and I/O: If the program needs to perform an input/output (I/O) operation—like reading a file from disk or displaying output—it must make a system call to the kernel. The kernel temporarily blocks the process, initiates the slow I/O operation, and allows the CPU to run other processes while the first one waits for the I/O to complete.
The Transformation: From Program to Process
The journey begins when a user interaction (like double-clicking an icon or typing a command) triggers a request to the kernel—the core of the OS. The program, which is a static file known as an executable (e.g., an ELF file or a PE file), is merely a sequence of instructions and data until the OS acts upon it.
Process Instantiation and Loading
- System Call: The shell or graphical environment issues a system call (like
execveon Linux orCreateProcesson Windows) to the OS kernel, requesting the execution of the program file. - Process Creation: The kernel creates a new administrative structure called the Process Control Block (PCB). The PCB is the process’s identity card, containing its unique Process ID (PID), its current state (ready, running, waiting), security permissions, and the values of its CPU registers.
- Virtual Memory Allocation: The OS allocates a virtual address space for the new process. This address space is a conceptual map that the program believes is its own contiguous memory, isolating it from other processes and protecting the kernel. The kernel then begins loading sections of the executable file from the slow disk storage into the faster Random Access Memory (RAM).
- Memory Segmentation: The program’s code and data are mapped into this virtual space in distinct segments:
- The Text Segment holds the actual machine code instructions (read-only).
- The Data Segment holds global and static variables.
- The Heap is reserved for dynamic memory allocated during runtime.
- The Stack is used to manage function calls, local variables, and return addresses (Last-In, First-Out).
Linking and Initialization
Before execution can begin, two final setup steps are performed:
- Dynamic Linking: Most modern programs rely on shared libraries (e.g.,
.dllor.sofiles) for common functions (like input/output, networking, or GUI drawing). The dynamic linker loads these necessary libraries into the process’s virtual address space and resolves all the external function calls, connecting the program to the system’s resources. - Entry Point: The OS initializes a special CPU register, the Program Counter (PC), to the memory address of the program’s first instruction (the “entry point,” often the
mainfunction).
Execution: The CPU’s Instruction Cycle
Once the process is loaded and initialized, the CPU Scheduler selects it to run on a processor core. The CPU then begins its fundamental work cycle, repeated billions of times per second:
- Fetch: The Control Unit uses the address stored in the Program Counter to retrieve the next machine code instruction from memory (RAM or the CPU’s cache).
- Decode: The instruction is translated into internal commands that the CPU’s components can understand and execute.
- Execute: The Arithmetic Logic Unit (ALU) or other specialized hardware performs the specified operation (e.g., addition, data movement, comparison, branching). The results are often temporarily stored in high-speed Registers within the CPU core.
- Write-Back: The final results are written back to a register or memory location.
Context Switching and I/O
The process does not run continuously. The OS ensures fairness and responsiveness through preemptive multitasking:
