What is a program: Set of instructions that the computer can execute. Can have multiple instances. |
What is a process: Task that you do on your computer, an instance of a program. Components: Executable program, associated data, execution context. |
Process image: current activity state reflected by CPU registers (PC, etc), Progam code, Data Sections (Global constants & variables), Stack, Heap |
Process elements: Identifier, State, Priority, Program Counter, Memory pointers, Context data, I/O States info, Accounting info |
Process control block (PCB): Data structure created & managed by OS, full of info about each process. New process created -> OS updates PCB with all process details, key tool that allows support for multiple processes. |
Dispatcher: Small OS that follows a scheduling policy, handles context switching for CPU, spends a lot of time saving instructions, load new instructions into CPU from PCB. Trace: Detailed log of what a process does |
Process Creation:App launch, OS start a process to do task, some process start in background w/o you directly interacting with them.Some processes are started by other processes. Parent process may wait for child to finish or continue concurrently. e.g Process A spawns other process & so forth forming a tree. |
Linux system calls: Fork(): Create copy of current process, exec():Execute a program, wait():Wait for child process to finish and change state, kill(): Send a signal to terminate a process, pipe(): IPC |
Two state (Running/Not Running) process model: Process created and move to queue -> Process stay till CPU is ready -> Dispatcher move a process from not running to running state -> Process is temporarily stopped, move back to not running state due to an interrupt -> If not, Process finish execution & leave the system. |
Five state process model: New, ready, running, blocked, exit |
five State transitions: New process is admitted to ready queue -> dispatcher assign process to be run by CPU -> If time out goes back to ready state -> If event wait (I/O completion), process admitted to block queue, event occurs, remove from block queue & move to ready queue to await dispatcher -> If process completes task, exits |
To handle different types of events, there can be multiple block queues. |
How does OS decide which process run when & how long: Scheduling policy (Dispatcher choose from ready queue for CPU to run), Dispatcher, Clock (timeout of process) |
Solutions for limited available memory: Virtual memory (Move part of a process from RAM to disk), Swapping (move some blocked processes entirely out to disk) |
Suspended queue: Process that are moved to disk is placed in a suspend queue, OS can decide to bring suspended processes back to main memory. |
Transition states: Same as five state processes but for processes in the block/ready queue, can be suspended and moved to disk (block/suspend & ready/suspend) if there are any memory constraints in RAM. Suspended processes can be moved back to the ready queue when there is enough memory to hold them or when an event they are waiting for occurs. |
Information required by OS to control processes and manage resources: Memory tables, I/O tables, File tables, Process tables |
Memory tables: RAM, Secondary memory (HDD/SDD), Virtual Memory. I/O Tables: Used by OS to manage I/O devices. File tables: Provide info about the existence of files location on secondary memory, current status and other attributes. |
Process tables: Process location (Where a process and its data is located in memory), Process Attributes (# Attributes used by OS for control) |
Process list structures: OS has a list of PCBs in each queue (running, ready, block) it use to keep track of all processes. |
Transitions: When a new process is created -> unique identifier assigned -> Memory space allocated for process image -> PCB is initialised -> set up linkage between parent and child processes -> Update all other data structures |
Process/Context switching: Necessary for multitasking. Occurs from a clock interrupt, I/O interrupt, Traps (Errors generated with running process), Supervisor call (User process calls for I/O operation & is blocked) |
Mode switching: User Mode (Where user applications run, Less privileged), Kernel Mode (Where the OS runs, Highly privileged) |
Costs involved for mode switching: Save state of current process, switch cpu to kernel mode to execute system call, restore state of process once system call is completed and switch back to user mode. |
Mode switch with process switch: Save context of processor -> Update PCB -> Move the PCB to the appropriate queue -> Select another process for execution -> Update the PCB of the process selected -> Update memory management data structures for address translation -> Restore the context of the processor to that which existed at the time the selected process was last switched out |
Mode switch w/o process switch: Interrupt is pending -> Save the context (PC, processor registers, stack pointer) into the PCB of the current process -> Sets the program counter to the starting address of an interrupt handler program -> Switches from user mode to kernel mode |
Traditional OS: All user processes rely on a single monolithic kernel |
Process switching functions: OS function executes within user processes. Mode switch w/o process switch in a user program (fopen()), Process switching function takes place when a process switches its state. |
process based OS: Processes are assigned different priorities to be scheduled for running, good for multi processor env |