OS provides process abstraction:)
- When you run an exe file, the OS creates a process = a running program
- OS timeshares CPU across multiple processes: virtualizes CPU
- OS has a CPU scheduler that picks one of the many active processes to execute on a CPU.
– Policy: which process to run
– Mechanism: how to “context switch” between processes
– Policy: which process to run
– Mechanism: how to “context switch” between processes
What constitutes a process:)
- A unique identifier PID)
- Memory image
– Code and data (static)
– Stack and heap (dynamic)
- File descriptors
– Pointers to open files and devices
– Code and data (static)
– Stack and heap (dynamic)
– Pointers to open files and devices
How does OS create a process?
- Allocates memory and creates memory image
– Loads code, data from disk exe,
– Creates runtime stack, heap
- Opens basic files – STD IN, OUT, ERR
- Initializes CPU registers
– PC points to first instruction
– Loads code, data from disk exe,
– Creates runtime stack, heap
– PC points to first instruction
States of a process
Dead: terminated
OS data structures
- OS maintains a data structure (e.g., list) of all active processes
- Information about each process is stored in a process control block (PCB).
– Process identifier
– Process state
– Pointers to other related processes (parent)
– CPU context of the process (saved when the process is suspended)
– Pointers to memory locations. – Pointers to open files
– Process identifier
– Process state
– Pointers to other related processes (parent)
– CPU context of the process (saved when the process is suspended)
– Pointers to memory locations. – Pointers to open files