04 Process Management
Process¶
Program in execution
Smallest unit of work
Types¶
- User processes
- System processes
Example¶
flowchart TB
P1 --> P2 & P3
P3 --> P4
Interpretations¶
- \(P_1\) spawns \(P_2\) and \(P_3\), and is their parent
- \(P_2\) and \(P_3\) are children of \(P_1\)
Program vs Process¶
Program | Process | |
---|---|---|
Active? | â (Passive) | â |
Requires resources? | â | â |
Segments required | Text (Code) | Text (Code) Data Stack Heap |
Type of memory required | Secondary | Primary |
Registers¶
Register | Pointer? | Stores |
---|---|---|
Base register | â | Starting address of process in Primary Memory |
Limit register | Length of the process | |
Flag register | ||
GPRs General purpose Registers | ||
PC Program Counter | â | Address of next instruction to be executed |
Index pointer | â |
Memory Layout of a Process¶
Segment | Stores |
---|---|
Text | Code |
Data | Global variables |
Stack | - Function Calls - Return address arguments - Local variables |
Heap | - Dynamic data - Data structures in memory |
Process State Transition Diagram¶
5-State¶
In very early systems that didnât have virtual memory
flowchart LR
New -->
|Admit| Ready -->
|Dispatch| Run -->
|Exit| Terminate
Run ----> |1. Timer Interrupt<br />2. Higher-Priority Process pre-empts| Ready
Run -->
|I/O<br/>Request| b[Blocked/<br/>Wait] -->
|I/O<br/>Complete| Ready
Jobs are picked by job scheduler and CPU scheduler
New \(\to\) Ready¶
Promoting a program into a process has some work associated with it for the OS
- Creates PCB
- Address space
(I missed some points)
7-State (Virtual Memory)¶
Further explanation has been uploaded on LMS
Similar to 5-State, but has 2 more states
- Blocked suspended: Wait for I/O or event; kept in secondary memory
- Ready Suspended: Wait for CPU but kept in secondary memory
Equivalent Names¶
- Activate = Swap-in
- Suspend = Swap-out
flowchart LR
ws[Wait<br/>Suspended]
rs[Ready<br/>Suspended]
New ----->
|Admit| Ready -->
|Dispatch| Run -->
|Exit| Terminate
Run ---> |1. Timer Interrupt<br />2. Higher-Priority Process pre-empts| Ready
Run -->
|I/O<br/>Request| b[Blocked/<br/>Wait] -->
|I/O<br/>Complete| Ready
rs -->|Activate| Ready -->|Suspend| rs
ws -->|I/O<br/>Complete| rs
ws --> |Activate| b --> |Suspend| ws
New -->|Preloading| rs
Wait \(\to\) Wait Suspended State¶
- In case all processes are in wait state (letâs say all are waiting for I/O)
- OS shifts some waiting processes into wait suspended queue (in secondary memory)
- Then, the OS brings in programs from the Job Queue (in secondary memory), and loads them into primary memory.
- There is ready and wait processes, but there isnât enough primary memory available
- So the OS shifts some waiting processes into wait suspended queue (in secondary memory) to free up some primary memory
Run \(\to\) Ready Suspended¶
- Processes in the ready or running state but are swapped out of main memory and placed in the disk
- The process will transition back to ready state whenever the process is again brought onto the main memory
New \(\to\) Ready¶
PCB address space
Just-in Time process
New \(\to\) Ready Suspended¶
Pre-emptive computations are performed
PCB, address space are generated before-hand
Some designers think it is necessary, others argue otherwise
PCB/TCB¶
Process/Task Control Block
It stores the Context of a Process
Whenever CPU requires details on any process, it will refer to PCB
Context of a Process¶
- State
- Process id \(\to\) unique number
- PC
- Register Contents
- Flag
- Index Pointer
- GPRs (General Purpose Registers)
- CPU Scheduling info
- Priority no
- Scheduling info
- Pointer to scheduling queues
- Memory management info
- Base register
- Limit register
- Virtual memory
- Page Table, Segment Table
- Accounting info
- Amt of CPU Time used
- I/O Info
- I/O devices alloted
- List of open file(s)
Context Switching¶
Whenever there is a switch from one process to another, the OS
- saves/stores the context of the previous process
- loads/restores the context of the current process
The âprocessâ can be a program/interrupt service routine; this interrupt can be Maskable/Non-Maskable Interrupt
Context-Switch Time¶
This is an overhead, as it is not âuseful workâ and is just âbook-keepingâ.
Depends on
- architecture of the system
- amount of âcontextâ information that is required to be stored/loaded
Process Scheduler¶
Job Scheduler | CPU Scheduler | Mid-Term | |
---|---|---|---|
Type | Long-Term | Short-Term | Medium-Term |
Executing Frequency | \(\downarrow\) | \(\uparrow\) (CPU Burst is faster) | |
Task | Selects processes to be loaded into Ready Queue | Allocates process from ready queue \(\to\) CPU | Swap-In Swap-Out |
Goal | Ensure good mix of CPU-Bound and I/O-Bound operations Controls degree of multi-programming | Ensure max CPU-utilization | Modify degree of multiprogramming |
Medium Term Scheduler Flowchart¶
Degree of multi-programming¶
No of programs kept in primary memory
CPU-I/O Bound¶
CPU-Bound | I/O-Bound |
---|---|
Process spends most of its time with CPU | Process spends most of its time in I/O operations |
Short burst time | Long burst time |
Overhead %¶
% time spent on scheduling decision
We want to minimize this.
Queues¶
Each queue has queue header containing pointers to the first and last PCBs of list
Job Queue¶
set of all processes in system
stored in secondary memory
Ready Queue¶
Processes that are ready to execute
Stored in primary memory
Device Queue¶
Set of processes waiting for I/O device
Queuing Diagram¶
Represents queues, resources and the corresponding flows
Very similar to state transition diagram, but the focus is on the queues
flowchart LR
jq[[Job Queue]] -->
|Admit| rq[[Ready Queue]] -->
|Dispatch| p[(CPU)] -->
|Release| r(( ))
p --> |Time-Out| rq
p -->
|I/O| bq[[Device Queue]] -->
rq