Processes and their implementation Flashcards
Independent processes
E.g. Four logical program counters switch by copying logical counter
Multiprogramming
E.g. Single physical program counter and flow of control
Logical program counters
Meant it stored record of where you were in program
Could split processes in parallel and switch between them using their logical program counter and storing what was there in the physical program counter.
Process Model
Central operating system concept - Everything built on process model
The abstraction of running program -
- many processes can run the same program
text
- each process has own address space
(isolation)
- a parent process can fork child processes
Provide pseudo concurrent operation even on single CPU (multiple virtual CPUs)
Independent sequential processes
Each process has own program counter, registers, variables and flow of control.
To run process, copy logical program counter into real physical program counter.
When switch, value of physical program counter is stored in process’ logical program counter in memory.
Processes over time
Over long period all processes make progress, at any given instance only one is active if single CPU.
CPUs switch rapidly between processes. Rate of progress isn’t uniform, predictable or reproducible.
Can’t make assumptions about timing, need special support for real-time systems.
Programs and processes
Program - Algorithm expressed in a programming language or other notation.
Process - Activity executing on a processor, has binary program text, input, output etc.
Interrupt and Switching
Another process requires CPU, save state of current process, switch to other process (may have higher priority or be next in line) with its own program and state.
2 processes may execute same program.
Processes and Multiprogramming
User runs video editor and web browser, background process periodically checks email.
OS shares processor time between processes - process blocks for I/O allows another process to use CPU
Long computation is divided up and suspended sometimes to give other processes a share of CPU
Suspended processes must restart in exactly same state -
OS saves address space and maintains process table entry for each process with information about resources in it.
Process resources
OS maintains resources for each process:
- Registers include program counter and stack pointer
- Open files
- Outstanding alarms, list of related processes etc.
Address space
OS allocates private address space to each process isolated from other processes:
Memory locations the process can read and write:
- Executable program text
- Program data
- The stack (one frame per active procedure or
function)
- Dynamically allocated memory
- Runtime environment
Processes and memory layout model
Stack
Heap
Unitialised data
Initialised data (global/static variables)
Text (program binary code)
Environment is fixed at run time, fixed set of data.
Program arguments are also fixed at runtime, includes things typed into command line like name of program.
Stack
Automatic (objects only exist for enclosing scope), managed by OS
Known at compile time (though usage determination by execution trace)
Heap
For flexibility for what can’t be known until runtime and what can’t fit on the stack.
More costly and error-prone (application programmer requests allocation/deallocation).
Process lifecycle and states
Processes have a lifecycle managed by OS:
- From creation to termination thorough
intermediate states.
- In simple systems all processes are created at
system startup. - In general-purpose systems need to create and
terminate processes during system operation.