In operating systems, processes are managed and controlled by the operating system kernel through various data structures and mechanisms. Three key components related to process management are process attributes, process tables, and the Process Control Block (PCB).
Process Attributes
Process attributes are characteristics associated with a process. They provide essential information about a process's state and behavior. Common process attributes include:
Process ID (PID): A unique identifier assigned to each process. PIDs help the operating system distinguish between different processes.
Program Counter (PC): A register that holds the memory address of the next instruction to be executed in the process's code.
Registers: CPU registers that store the current values of various processor state elements, including general-purpose registers and status flags.
Priority: A priority value that determines a process's importance or scheduling priority in a multi-tasking environment.
State: Indicates the current state of the process (e.g., running, ready, waiting, terminated).
Parent Process ID: The PID of the process that created (parented) the current process.
Memory Information: Information about the memory allocated to the process, including the base address, size, and page tables.
File Descriptors: A list of open files and their associated file descriptors.
Process Table
A process table is a data structure maintained by the operating system to keep track of information about all the processes currently running or existing on the system. Each entry in the process table corresponds to a single process and contains details about that process, such as its PID and a reference to its PCB.
The process table is essential for process management tasks, including process creation, termination, scheduling, and resource allocation. It allows the operating system to efficiently locate and manage processes as they execute.
Process Control Block (PCB):
A Process Control Block (PCB), also known as a Task Control Block (TCB), is a data structure associated with each process. It contains detailed information about the state and attributes of a specific process. The PCB is managed by the operating system kernel and is used during context switching and process scheduling. Key information stored in a PCB includes:
Process state and status information (e.g., running, ready, blocked).
Program counter
CPU registers
Process ID (PID) and parent process ID.
Process priority and scheduling information.
File descriptors and I/O status.
Signal and interrupt handling information.
During context switching (when the operating system switches from one process to another), the contents of the CPU registers are saved in the PCB of the currently running process, and the registers are loaded with the values from the PCB of the process being switched to. This ensures that the state of the previous process is preserved, allowing it to resume execution later.
Context Switching
Context switching in an operating system involves saving the context or state of a running process so that it can be restored later, and then loading the context or state of another process and run it¹. Context switching refers to the process/method used by the system to change the process from one state to another using the CPUs present in the system to perform its job¹. It enables all processes to share a single CPU to finish their execution and store the status of the system’s tasks¹. The execution of the process begins at the same place where there is a conflict when the process is reloaded into the system¹. The operating system's need for context switching is explained by the reasons listed below:
One process does not directly switch to another within the system.
Context switching makes it easier for the operating system to use the CPU’s resources to carry out its tasks and store its context while switching between multiple processes.
Context switching only allows a single CPU to handle multiple processes requests parallelly without the need for any additional processors¹.
The three different categories of context-switching triggers are as follows:
Interrupts: When a CPU requests that data be read from a disc, if any interruptions occur, context switching automatically switches to a component of the hardware that can handle the interruptions more quickly.
Multitasking: The ability for a process to be switched from the CPU so that another process can run is known as context switching. When a process is switched, the previous state is retained so that the process can continue running at the same spot in the system.
Kernel/User Switch: This trigger is used when the OS needed to switch between user mode and kernel mode. When switching between user mode and kernel/user mode is necessary, operating systems use the kernel/user switch¹.
Last updated