A process in computing is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system, a process may be made up of multiple threads of execution that execute instructions concurrently.
Process States: During its
lifecycle, a process can be in one of the following states:
- New: The process is being created.
- Ready: The process is loaded into main
memory and is waiting to execute.
- Running: Instructions are being executed.
- Blocked (or Waiting): The process is waiting
for some event to occur (such as an I/O operation to complete).
- Terminated (or Exit): The process has
finished execution.
The state of a process is
typically stored in a data structure called a Process Control Block (PCB).
Process Control Block (PCB):
A PCB is a data structure maintained by the operating system for every process.
It contains various details about the process, including:
- Process ID: A unique identifier for the
process.
- Process State: The current state of the
process (new, ready, running, etc.).
- Process Priority: Information about the
process's priority.
- CPU Registers: The values of the processor's
registers.
- CPU Scheduling Information: Information
required for scheduling the process. This may include the priority of the
process, pointers to scheduling queues, and other scheduling parameters.
- Memory Management Information: This may
include information such as the base and limit registers and page tables,
depending on the memory system used by the OS.
- Accounting Information: This includes the
amount of processor and clock time used, time limits, account numbers, job
or process numbers, etc.
- I/O Status Information: This includes the
list of I/O devices allocated to the process, a list of open files, etc.
When a process is switched out of
the CPU (during a context switch), its PCB is used to save the state of the
process so it can be restarted later from where it left off.