Process management Information maintained by OS for process

Process management  Information maintained by OS for process

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 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. Process context

MAX stack Contains all states necessary to run a program The information the process needs to do the job: code, data, stack, heap. heap data

This is known as User level context. text (code) 0 Process in memory User level contextMAX int aa; char buf[1000]; void foo() { int a; } main() { int b; char *p;

p = new char[1000]; foo(); } (b, *p) - main (a) - foo heap (p) (char[1000]) data (aa, buf) text (code) 0 Process memory stack 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. P1 P2 R0 = 1 R0 = 2 R2 = R0 + 1 R2 = R0 R2 in P1 is wrong. How to make It 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! 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. Why is process context important? To run a process correctly, the process instructions must be executed within the process context!

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 An example PCB Figure 3.3 OS CPU abstraction Hardware reality:

One CPU runs the fetchexecute algorithm OS abstraction: Each process has one CPU, running the fetchexecute algorithm for the process. Each process executes within its context. Load PC; IR = MEM[PC]; While (IR != HALT) { PC ++;

Execute IR; IR = MEM[PC]; } 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 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, x0, x1, x2, [store Xs context], [restore Ys context] y0, y1, y2 OS must do this to keep programs execute within its context: Context switching Dispatching Loop The hardware view of the system execution: dispatching loop

LOOP Context Switch: Dispatcher code Run process Save process states Choose a new process to run Load states for the chosen process Scheduling

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? How Does the Dispatcher Regain Control? Two ways:

1. Internal events 2. A process is waiting for I/O A process is waiting for some other process Yielda process gives up CPU voluntarily External events Interruptsa complete disk request

Timerits like an alarm clock What States Should a process save? Anything that the next process may trash Program counter Registers Etc. 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. Process States

A process is typically in one of the three states 1. 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

Recently Viewed Presentations

  • U.S. General Services Administration Federal Acquisition Service Networx

    U.S. General Services Administration Federal Acquisition Service Networx

    Times Arial Narrow Wingdings Arial ヒラギノ角ゴ Pro W3 Franklin Gothic Medium Times New Roman Networx Unit Pricer Training Manual 07172007 Slide 1 Networx Unit Pricer — Released Prices Main Page Navigation and Selection Basics Box 1 - Choose Your Vendors...
  • Production Plant Layout (1)

    Production Plant Layout (1)

    Production Plant Layout (1) Facility Layout Problem: design problem locations of activities dimensions configurations No overall algorithm exists Production Plant Layout (2) Reasons: new products changes in demand changes in product design new machines bottlenecks too large buffers too long...
  • Title: Slide 1 Author: Jim McEwen Last modified by: Rebecca Mather Created Date: 11/11/2009 3:55:53 PM Document presentation format: On-screen Show (4:3)
  • Don't Be Envious of Evil Men - Oologah church of Christ

    Don't Be Envious of Evil Men - Oologah church of Christ

    I acquired male and female singers, the delights of the sons of men, and musical instruments of all kinds. ... In time their joys will come to an end. Do not fret because of evildoers, ... Don't Be Envious of...
  • PN modelling - University of Liverpool

    PN modelling - University of Liverpool

    The Four Seasons. COMP201 - Software Engineering. Let us try to model the four seasons of the year together with their properties by a Petri net. We would like to denote the current season {spring, summer, autumn, winter}, the temperature...
  • Catastrophism, Uniformitarianism, and Gradualism

    Catastrophism, Uniformitarianism, and Gradualism

    Catastrophism, Uniformitarianism, and Gradualism ... Wikimedia Commons Evidence of mountain-building Charles Lyell Principles of Geology "The present is the key to the past." Much better writer than Hutton; disseminated idea of Uniformitarianism to a much wider audience Lyell and Darwin...
  • Oxyfuel Troubleshooting - marshall.k12.mn.us

    Oxyfuel Troubleshooting - marshall.k12.mn.us

    Oxyfuel Troubleshooting Subject: Oxyfuel Gas Welding & Cutting Author: Arthur B. Papineau ... CommonBullets Symbol Slide 2003 Microsoft Excel Worksheet Oxy Fuel Welding Welding Flame Types Weld Quality Welding Troubleshooting Brazing Flame Types Soldering Flame Types Cutting Flame Types Cut...
  • Lab & Cooking Safety - Weebly

    Lab & Cooking Safety - Weebly

    Science Lab Safety. No horseplay. No sitting (while doing most labs) No food or drinks. Science Lab Safety. Don't taste anything (unless told to do so) Science Lab Safety. Never, ever directly smell something in the lab! ... Lab &...