Context
On path: Processes | 1: Processes • 2: Context • 3: Process Control Block (PCB) • 4: Multi Threading • 5: Threads • 6: Interprocess Communication • 7: Process Scheduling • 8: Scheduler • 9: Process States • 10: Process Priority |
---|
On path: OS Topics | 1: Concepts • 2: Cache • 3: Context • 4: Processor Privilege • 5: Process Scheduling • 6: Exceptions • 7: Interrupts • 8: Direct Memory Access (DMA) • 9: Virtualisation • 10: Hypervisor |
---|
Depends on | Processes • Security |
---|
Caution: not all the terms used here may be familiar on a first visit.
An executing process will have a particular context. This is the environment in which it operates, and includes its variables – in memory or processor registers – and the resources which it ‘owns’.
Most of this will be kept in the main memory of the computer. The main memory is (in some sense) ‘large’ and can accommodate several processes simultaneously. In addition to the memory assigned to a process, there are usually some resources which need to be shared. One example – probably already familiar – is that the processor running the code has some ‘registers’ which store variables temporarily during execution. There will also be some ‘resources’ (such as particular files in use) which the O.S. keeps track of.
This figure assumes a virtual memory system which shares the physical memory amongst processes. In the figure the blue process is currently executing. It occupies the processor and the virtual address space; if it is not too ‘hungry’ for space it will share the pages of the physical memory with other (not-executing-at-this-moment) processes.
There will be a Process Control Block (PCB) associated with the process; this holds (or points to) information such as the process’ identity, parent, priority, resources it is holding (such as memory, peripherals etc.) etc.
Register values are part of the process’ context; thus they require saving (in some reserved memory, by the OS) whenever the running process changes. This is part of the process of context switching.
A simple processor (best to stick to a simple processor to start with!) can only run one process at a time. If your computer is running several processes ‘simultaneously’ it is therefore running one for a (short) time, then context switching to another and so on. This is done fast enough for a human not to notice the stop-start behaviour although your ‘favourite’ process may perceptibly slow down if the machine is very busy as it gets a lesser share of processor time.
More details
A process’ full context includes:
- state held within the processor (‘registers’ etc.).
- the memory management page tables.
- a list of resources owned by that process.
- any specific cached information