The process
- Passive entity vs active entity.
- A process is a program in execution
- A program becomes a process when an executable file is loaded into memory.
- A program may have several processes running
- The process itself can be an execution environment for other code.
Address Space
- Text section - the program code
- Process stack - contains temporary data (such as function parameters, return addresses, and local variables)
- Data section - contains global variables
- Heap - memory that is dynamically allocated during process run time.
Process State
As a process executes, it changes state. The state of a process is defined in part by the current activity of that process. A process may be in one of the following states:
- New - The process is being created.
- Running - Instructions are being executed
- Waiting - The process is waiting for some event to occur (such as an I/O completion or reception of a signal)
- Ready -The process is waiting to be assigned to aprocessor
- Terminated - The process has finished execution
Process Control Block
Each process is represented in the operating system by a process control block (PCB) — also called a task control block
- Process state: new, ready, running, waiting, halted, and so on.
- Program counter: it indicates the address of the next instruction to be executed for this process.
- CPU Registers
- CPU-scheduling information - This information includes a process priority, pointers to scheduling queues, and any other scheduling parameters.
- Memory management information
- Accounting info
- I/O status information
- PCB is created when process is created
- Certain fields are updated when process state changes
In brief, the PCB simply serves as the repository for any information that may vary from process to process.
Context Switch
- Switching the CPU from the content of one process of the content of another
- They are expensive
- Direct costs: number of cycles for store instructions
- Indirect costs: cold cache, cache missies
Process Creation
Mechanisms for process creation
Fork
- Copy the parent PCB into new child PCB
- Child continues execution at instruction after work
Exec
- Replace child image
- Load new program and start from first instruction