- When a program is loaded into memory, it becomes a process.
- an entity which represents the basic unit of work to be implemented in the system.
Program vs Process
A process is a program in execution. For example, when we write a program in C or C++ and compile it, the compiler creates binary code. The original code and binary code are both programs. When we actually run the binary code, it becomes a process.
A process is an ‘active’ entity, as opposed to a program, which is considered to be a ‘passive’ entity. A single program can create many processes when run multiple times; for example, when we open a .exe or binary file multiple times, multiple instances begin (multiple processes are created).
Four sections of a process: Stack, Heap, Text and Data
Text Section: A Process, sometimes known as the Text Section, also includes the current activity represented by the value of the program counter.
Stack: The Stack contains the temporary data, such as function parameters, returns addresses, and local variables.
Data Section: Contains the global variable and static variables.
Heap Section: Dynamically allocated memory to process during its run time.
Process Life Cycle
- Start: This is the initial state when a process is first started/created.
- Ready: The process is waiting to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by the operating system so that they can run. Process may come into this state after Start state or while running it by but interrupted by the scheduler to assign CPU to some other process.
- Running: Once the process has been assigned to a processor by the OS scheduler, the process state is set to running and the processor executes its instructions.
- Waiting: Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input, or waiting for a file to become available.
- Terminated or Exit: Once the process finishes its execution, or it is terminated by the operating system, it is moved to the terminated state where it waits to be removed from main memory.
Process Control Block(PCB)
- Process State: The current state of the process i.e., whether it is ready, running, waiting, or whatever.
- Process ID: Unique identification for each of the process in the operating system.
- Pointer: A pointer to parent process.
- Program Counter: Program Counter is a pointer to the address of the next instruction to be executed for this process.
- CPU registers: Various CPU registers where process need to be stored for execution for running state.
- CPU Scheduling Information: Process priority and other scheduling information which is required to schedule the process.
- Memory management information: This includes the information of page table, memory limits, Segment table depending on memory used by the operating system
- Accounting information: This includes the amount of CPU used for process execution, time limits, execution ID etc.
- IO status information: This includes a list of I/O devices allocated to the process
The PCB is maintained for a process throughout its lifetime, and is deleted once the process terminates