Professional Documents
Culture Documents
Information Maintained by OS For Process Management
Information Maintained by OS For Process Management
management
process context
Context switching
Dispatching loop
Process
a program in execution
Process context
MAX stack
The information the process needs to do the job: code, data, stack, heap.
heap
data
text (code)
Process in memory
(a) - foo
stack
text (code) 0
Process memory
Process context
P1 P2
R0 = 1
R0 = 2
R2 = R0 + 1
R2 = R0
Only if the system runs through one program at a time The system typically needs to switch back and forth between programs.
Process context:
Register context (R0, R1,, PC, stack pointer, PSW, etc). What else?
To run a process correctly, the process instructions must be executed within the process context!
User level context is in memory. Other context information is stored in a data structure called process control block. The OS has a process control block table. For each process, there is one entry in the table. Process control block also contains other information that the OS needs to manage the processes.
An example PCB
Figure 3.3
OS CPU abstraction
Hardware reality:
OS abstraction:
Load PC; IR = MEM[PC]; While (IR != HALT) { PC ++; Execute IR; IR = MEM[PC]; }
Each process has one CPU, running the fetchexecute algorithm for the process. Each process executes within its context.
OS CPU abstraction
Hardware instructions? x0, x1, x2, y0, y1, y2, z0, z1, z2, x3, x4, x5, Does this embedding work? No!! Instructions in a process should only be executed within the processs context to be correct.
OS CPU abstraction
Process X instructions: x0, x1, x2, . Process Y instructions: y0, y1, y2, Process Z instructions: z0, z1, z2,
OS must do this to keep programs execute within its context: Context switching
Dispatching Loop
LOOP
Run process Save process states Choose a new process to run Load states for the chosen process
Scheduling
How does the dispatcher (OS) regain control after a process starts running? What states should a process save? How does the dispatcher choose the next thread?
Two ways:
1.
Internal events
A process is waiting for I/O A process is waiting for some other process Yielda process gives up CPU voluntarily
2.
External events
The dispatcher keeps a list of processes that are ready to run If no processes are ready
Otherwise, the dispatcher uses a scheduling algorithm to find the next process.
Process States
2.
3.
Running: has the CPU Blocked: waiting for I/O or another thread Ready to run: on the ready list, waiting for the CPU
Figure 3.2