The execution context involves the following steps:-
Stack Setup
The stack pointer is setup with the new process's arguments and environment variables. The new stack layout typically includes the argument strings, environment strings, and auxiliary vectors.
Program Counter Initialisation
The instruction pointer(program counter) is set to the entry point of the new executable which is usually the address of '__start' function in ELF header.
Registers and flags
The CPU registers are reset to their initial states and certain flags and control registers are setup to reflect the new process's execution context.
The following steps are involved in replacing the old process context with the new one:-
Memory Mapping Update
The old memory mappings in the 'mm_struct' are replaced with the new memory mappings . The kernel updates the page tables to reflect the new memory layout.
Task Struct Update
The task_struct is updated with information about the new executable. This includes updating the file descriptor table, signal handlers and other process-related information.
Start Execution
The control is transferred to the new program's entry point. The new program starts executing, and the old one is completely replaced.