Top Banner
Process management Information maintained by OS for process management process context process control block OS virtualization of CPU for each process. Context switching Dispatching loop
20

[PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

May 03, 2018

Download

Documents

hadan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Process management

Information maintained by OS for process management

process context process control block

OS virtualization of CPU for each process. Context switching Dispatching loop

Page 2: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Process

a program in execution We should know about processes by now.

How does the OS correctly run multiple processes concurrently?

What kind of information to be kept? What does the OS have to do in order to run processes correctly.

Page 3: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Process context

Contains all states necessary to run a program The information the

process needs to do the job: code, data, stack, heap. This is known as User

level context.

stack

heap

data text (code) 0

MAX

Process in memory

Page 4: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

User level context (b, *p) - main (a) - foo

heap (p) (char[1000])

data (aa, buf) text (code) 0

MAX

Process memory

…int aa;char buf[1000];void foo() { int a; … }main() { int b; char *p; p = new char[1000]; foo();}

stack

Page 5: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Process context

Contains all states necessary to run a program Is the user level

context sufficient? Only if the system runs

through one program at a time

The system typically needs to switch back and forth between programs.

R0 = 1

R2 = R0 + 1

R0 = 2

R2 = R0

P1 P2

• R2 in P1 is wrong. How to makeIt correct?

• Save R0 in P1 before switching• Restore R0 in P1 when switching from P2 to P1.

• Registers should be a part of process context: the register context!

Page 6: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Process context: User level context

Code, data, stack, heap Register context (R0, R1,…, PC, stack

pointer, PSW, etc). What else?

OS resources. E.g open files, signal related data structures, etc.

Page 7: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Why is process context important?

To run a process correctly, the process instructions must be executed within the process context!

Page 8: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Where is the process context stored? 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. Process status (running, waiting, etc) Process priority ……

Page 9: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Figure 3.3

An example PCB

Page 10: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

OS CPU abstraction

Hardware reality: One CPU runs the fetch-

execute algorithm

OS abstraction: Each process has one

CPU, running the fetch-execute algorithm for the process.

Each process executes within its context.

Load PC;IR = MEM[PC];While (IR != HALT) { PC ++; Execute IR; IR = MEM[PC];}

Page 11: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

OS CPU abstraction

What does the OS have to do? Embed the process instruction sequence

into hardware instruction sequence.Process X instructions: x0, x1, x2, ….Process Y instructions: y0, y1, y2, …Process Z instructions: z0, z1, z2, …

Hardware instructions? x0, x1, x2, y0, y1, y2, z0, z1, z2, x3, x4, x5, …

Does this embedding work? No!! Instructions in a process should onlybe executed within the process’s context to be correct.

Page 12: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

OS CPU abstractionProcess X instructions: x0, x1, x2, ….Process Y instructions: y0, y1, y2, …Process Z instructions: z0, z1, z2, …

x0, x1, x2, [store X’s context], [restore Y’s context] y0, y1, y2…

OS must do this to keep programs execute within its context: Context switching

Page 13: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization
Page 14: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Dispatching Loop

The hardware view of the system execution: dispatching loop LOOP

Run process Save process states Choose a new process to run Load states for the chosen process

Context Switch:Dispatchercode

Scheduling

Page 15: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Simple? Not Quite…

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?

Page 16: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

How Does the Dispatcher Regain Control?

Two ways:1. Internal events

A process is waiting for I/O A process is waiting for some other process Yield—a process gives up CPU voluntarily

2. External events Interrupts—a complete disk request Timer—it’s like an alarm clock

Page 17: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

What States Should a process save?

Anything that the next process may trash Program counter Registers Etc.

Page 18: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

How Does the Dispatcher Choose the Next process?

The dispatcher keeps a list of processes that are ready to run

If no processes are ready Dispatcher just loops

Otherwise, the dispatcher uses a scheduling algorithm to find the next process.

Page 19: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Process States

A process is typically in one of the three states

1. Running: has the CPU2. Blocked: waiting for I/O or another

thread3. Ready to run: on the ready list, waiting

for the CPU

Page 20: [PPT]PowerPoint Presentation - Computer Science, FSU · Web viewProcess management Information maintained by OS for process management process context process control block OS virtualization

Figure 3.2