A process is an active instance of a program being executed, also referred to as an "active entity". When a program is executed, the operating system creates or manages a process for that program. The process represents the running instance and has resources and state associated with it, such as its memory/address space, CPU registers such as the program counter and stack pointer, open files and devices, scheduling information, protection and access information, and process ID (PID). The information representing the process's current execution state is commonly referred to as its process context. This includes information such as CPU register values, the program counter and the stack pointer, which must be preserved when the process stops executing so that it can later resume from where it left off. The operating system maintains information about each process in a data structure called the Process Control Block (PCB). The PCB contains information the operating system needs to identify, manage, schedule and keep track of the process, as well as information needed to save and restore its execution state. This can include the process ID (PID), process state, scheduling information, memory-management information and saved CPU state. If the same program is executed several times, multiple processes may be created for that program. This means that one program can have multiple processes.
- Memory / Address Space: The virtual address space available to the process, containing the memory used by the process during execution.
- CPU Registers: The values currently held in CPU registers on behalf of the process. These values form part of the process's execution state and may need to be saved and restored when the operating system switches between processes. Important registers include the program counter and stack pointer, which are described separately below.
- Program Counter: A CPU register that identifies the location of the next instruction to be executed for the process. Its value must be preserved when a process stops executing so that the process can later resume execution.
- Stack Pointer: A CPU register containing the memory address of the current top of the process's stack. Like other parts of the CPU state, its value must be saved when the process stops executing and restored when the process resumes.
- Open Files and Devices: Resources that the process has opened or is using, such as files, network sockets and I/O devices. The operating system maintains information that allows the process to access these resources.
- Scheduling Information: Information used by the operating system's scheduler when determining when the process should execute. This can include information such as the process's priority and scheduling policy.
- Protection and Access Information: Information used by the operating system to determine which resources and operations the process is permitted to access. This helps prevent processes from accessing protected memory or resources without permission.
- Process ID (PID): A numerical identifier assigned to the process by the operating system. The PID allows the operating system and other programs to identify and refer to a particular process.
A process's address space typically contains several regions, including the text (code), data, heap, stack, shared libraries, and memory-mapped regions. Each region serves a different purpose and is assigned a range of virtual addresses within the process's address space. The amount of memory used by some of these regions can change during the lifetime of the process depending on the requirements of the program.
Once a process is created it can be in one of several states:
- New state - when the process is created and initialised by the operating system
- Ready state - when the process is ready to execute and is waiting for CPU time. If the CPU becomes available and the operating system's scheduler selects the process, it can begin or resume execution
- Running state - when the process's instructions are currently being executed by the CPU
- Waiting or Blocked state - when the process cannot continue executing until an event occurs. For example, it may be waiting for an I/O operation to complete or for input from the user
- Terminated state - when the process has completed its execution or has otherwise been terminated by the operating system
- Suspended Ready state - when the process is ready to execute but has been suspended, typically with some or all of its memory swapped out of primary memory to secondary storage. It cannot be selected for execution until it is brought back into primary memory and returned to the Ready state
- Suspended Waiting/Blocked state - when the process has been suspended and is also waiting for an event, such as an I/O operation, to occur. Even if the event occurs, the process cannot execute immediately because it must first be brought back into primary memory. Once the event it was waiting for has occurred, it can move to the Suspended Ready state