Processes are programs in execution (by CPU, in sequential fashion). They are different from threads.processes-overview.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
Processes
Operations
Creation
Scheduling
Communication
Termination
Medium-term
Long-term
Schedulers
Short-term
Queues
Shared Memory
Message Passing
IPC
Child Processes
Spawn
Fork
Operations
PCB
Link to original
Processes can:
- be created
- be scheduled
- be terminated
- communicate with each other
Processes can be batch or time-shared
process.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
Stack
Heap
Data
Text
Local Variables, function return values
Dynamic Memory
Global/Static variables
Compiled Program (Loaded from NVS)
Stackoverflow!
Link to original
Stack - stores local variables. Variables are pushed at the start of scope and popped off at end:
int test(){ \\ <---- start of scope
int var = 0; \\ <---- Local variable pushed to stack
} \\ <----- Local variable pushed to stack at end of scopeHeap - dynamic memory allocation. They are managed via calls to new , delete , malloc, free
Data - global/static variables, initialized before main
Text - compiled program, loaded from Non-volatile Storage (NVS)
Operations
Creation
Child Processes
Processes can fork or spawn child processes. There are many concerns when it comes to child processes:
- Resource Sharing
Resource Sharing
3 Approaches:
- Parent and children share all resources
- Chidren share subset of parents resources
- Parent and Child share no resource
resource-sharing.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
Parent
Child
Parent
Child
Parent
Child
All
Subset
None
Link to original
Execution Type
Parent and children execute concurrently Parent awaits until child terminates (asynchronously)
forking.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
Fork
Exec
Wait
Exit
Link to original
Address Space
- child duplicate of parent
- child ha a program loaded
Scheduling
States
Process can be in any of 5 states:
- new - created
- ready - waiting to be assigned to processor
- running - executing in processor
- waiting - waiting for I/O, IPC message, timer or child process to finish
- terminated - finished or killed
Queues
A device can either be I/O bound or CPU bound CPU bound - few long CPU bursts I/O bound - many short CPU bursts
cpu-bound-vs-io-bound.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
I/O Bound
CPU Bound
Link to original
An efficient scheduling system will select a mix of both
ready queue - in main memory, waiting for CPU device queue - waiting for I/O
Schedulers
process-state-cycle.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
new
ready
running
waiting
terminated
medium-term
short-term
I/O Event
medium-term
exit
admitted
Long-term
Short-term
Medium-term
Link to original
3 types of schedulers:
- long-term - controls degree of “multiprogramming”, moves from memory to ready queue
- medium-term - swaps out running processes for others (due to timeslice, priority or otherwise)
- short-term - moves from ready queue to running
Context Switching
context-switch.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
P
0
P
1
Reload PC
Reload PC
Idle
Idle
Save PC
Save PC
Link to original
PCB
pcb.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
Pointer
Process State
Process Number
Program Counter
Registers
List of Open files
Link to original
Communication
IPC
Processes can be:
- Independent
- Cooperating
- Information Sharing - access to same resources
- computation speedup - break down problem into subproblems parallel computing
- modularity - efficient OS by breaking down into cooperation
- convenience - user running same process multiple times
Two methods of IPC:
| Shared Memory | Message Passing |
|---|---|
| + Faster | - system call every transfer slower |
| - Complicated to setup | - simpler to setup (even across different comptuers) |
| - Don’t work across multiple computers | = for multiple comptuers / small, infrequent data |
| = For Large amounts of data | |
in-memory-ipc.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
P0
P1
Kernel
Link to original
message-passing.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
P0
P1
Kernel
Shared Memory
Link to original
Message Passing
Messages can be:
- Blocking (synchronous) - sender or receiver wait until message has been sent/received
- Non-blocking (asynchronous) - sender will send message and continue/receiver receives valid message or null
Shared Memory
Termination
Two methods:
- Process requests OS to delete it → output data from child to parent → process deallocated by OS
- Parent terminates child (abort), can happen for many reasons:
- Child exceeded allocated resource
- task assigned no longer needed
- parent exiting
Cascading termination - all children terminate