1 Operating Systems and Protection CS 217. 2 Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Chapter 3 Process Description and Control
Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
1 Processes Professor Jennifer Rexford
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Processes CSCI 444/544 Operating Systems Fall 2008.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
1 Operating Systems and Protection Professor Jennifer Rexford CS 217.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
Review: Operating System Manages all system resources ALU Memory I/O Files Objectives: Security Efficiency Convenience.
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Computer Organization and Architecture
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
OS Spring’04 Introduction Operating Systems Spring 2004.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
1 Memory Hierarchy Professor Jennifer Rexford
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Introduction to Embedded Systems
Protection and the Kernel: Mode, Space, and Context.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Implementing Processes and Process Management Brian Bershad.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
Chapter 3 Process Description and Control
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Processes Introduction to Operating Systems: Module 3.
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
Concurrency & Context Switching Process Control Block What's in it and why? How is it used? Who sees it? 5 State Process Model State Labels. Causes of.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
LINUX System : Lecture 7 Process Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System.
Chapter 4 Process Abstraction Chien-Chung Shen CIS, UD
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
Processes 2 Introduction to Operating Systems: Module 4.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems Concepts
Processes and threads.
Virtualization Virtualize hardware resources through abstraction CPU
Operating Systems CMPSC 473
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
William Stallings Computer Organization and Architecture
Intro to Processes CSSE 332 Operating Systems
x86 segmentation, page tables, and interrupts
Process & its States Lecture 5.
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
CSCE 313 – Introduction to UNIx process
Exceptions and Processes
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Operating Systems: A Modern Perspective, Chapter 6
Processes in Unix and Windows
Memory Management Jennifer Rexford.
Presentation transcript:

1 Operating Systems and Protection CS 217

2 Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process control block  Virtual memory Boundary between parts of the system  User programs  Operating system  Underlying hardware Mechanics of handling a page fault  Page tables  Process ID registers  Page faults

3 Operating System Supports virtual machines  Promises each process the illusion of having whole machine to itself Provides services:  Protection  Scheduling  Memory management  File systems  Synchronization  etc. Hardware Operating System User Process User Process

4 What is a Process? A process is a running program with its own …  Processor state –EIP, EFLAGS, registers  Address space (memory) –Text, bss, data, heap, stack Supporting the abstraction  Processor –Saving state per process –Context switching  Main memory –Sharing physical memory –Supporting virtual memory  Efficiency, fairness, protection Hardware Operating System User Process User Process

5 Divide Hardware into Little Pieces? Idea: registers, memory, ALU, etc. per process  Pro: totally independent operation of each process  Con: lots of extra hardware; some parts idle at any given time; hard limit on the number of processes Operating System User Process User Process Hardware

6 Indirection, and Sharing in Time? Idea: swap processes in and out of the CPU; map references into physical addresses  Pro: make effective use of the resources by sharing  Con: overhead of swapping processes; overhead of mapping memory references Hardware Operating System User Process User Process

7 When to Change Which Process is Running? When a process is stalled waiting for I/O  Better utilize the CPU, e.g., while waiting for disk access When a process has been running for a while  Sharing on a fine time scale to give each process the illusion of running on its own machine  Trade-off efficiency for a finer granularity of fairness CPU I/O 1: CPU I/O 2:

8 Life Cycle of a Process Running: instructions are being executed Waiting: waiting for some event (e.g., I/O finish) Ready: ready to be assigned to a processor CreateReadyRunningTermination Waiting

9 Switching Between Processes Running Save context Load context Save context Load context RunningWaiting Process 1 Process 2

10 Context Switch: What to Save & Load? Process state  New, ready, waiting, halted CPU registers  EIP, EFLAGS, EAX, EBX, … I/O status information  Open files, I/O requests, … Memory management information  Page tables Accounting information  Time limits, group ID,... CPU scheduling information  Priority, queues

11 Process Control Block For each process, the OS keeps track of...  Process state  CPU registers  CPU scheduling information  Memory management information  Accounting information  I/O status information ready EIP EFLAGS EAX EBX... etc. PCB3 PCB2 PCB1 OS’s memory Process 1’s memory Process 2’s memory Process 3’s memory

12 Sharing Memory In the old days…  MS-DOS (1990)  Original Apple Macintosh (1984) Problem: protection  What prevents process 1 from reading/writing process 3’s memory?  What prevents process 2 from reading/writing OS’s memory? In modern days, Virtual Memory protection  IBM VM-370 (1970)  UNIX (1975)  MS Windows (2000) PCB3 PCB2 PCB1 OS’s memory Process 1’s memory Process 2’s memory Process 3’s memory

13 Virtual Memory Give each process illusion of large address space  E.g., 32-bit addresses that reference 4 Gig of memory Divide the physical memory into fixed-sized pages  E.g., 4 Kilobyte pages Swap pages between disk and main memory  Bring in a page when a process accesses the space  May require swapping out a page already in memory Keep track of where pages are stored in memory  Maintain a page table for each process to do mapping Treat address as page number and offset in page  High-order bits refer to the page  Low-order bits refer to the offset in the page

14 Virtual Memory for a Process Virtual Address SpacePhysical Address Space Address Translation address 0 virtual page number offset in page physical page number offset in page

15 Virtual Memory Process 2 Virtual Address Space Physical Address Space 0 1 Process 1 Virtual Address Space OS V.A.S. 0 1

16 Page Tables Process 1 Virtual Address Space Physical Address Space 0 1 Process 2 Virtual Address Space Process Number OS V.A.S.

17 Page Tables Reside in Memory... Process 1 Virtual Address Space Physical Address Space 0 1 Process 2 Virtual Address Space OS V.A.S.

18 Process ID Register Physical Address Space Process Process ID address virtual page number offset in page

19 Protection Between Processes Process Process ID address virtual page number offset in page User-mode (unprivileged) process cannot modify Process ID register If page tables are set up correctly, process #1 can access only its own pages in physical memory The operating system sets up the page tables

20 Paging Process xx Process ID address virtual page number offset in page Physical Address Space

21 Page Fault! Process xx Process ID Physical Address Space movl , %eax

22 Write Some Other Page to Disk Process yy 2 xx Process ID Physical Address Space movl , %eax 2

23 Fetch Current Page, Adjust Page Tables Process yy Process ID Physical Address Space movl , %eax

24 Measuring the Memory Usage % ps l F UID PID PPID PRI VSZ RSS STAT TIME COMMAND SN 0:00 -csh SN 5:52 emacs RN 0:00 ps l Virtual memory usage Physical memory usage (“resident set size”) CPU time used by this process so far Unix Windows

25 Context Switch, in More Detail Running Save context Load context Save context Load context RunningWaiting Process 1 Process 2

26 Context Switch, in More Detail Running Waiting Process 1 addl %eax, %ecx movl –8(%ebp), %eax addl %eax, %ecx. page fault PCB3 PCB2 PCB1 OS’s memory Process 1’s memory Registers

27 Context Switch, in More Detail addl %eax, %ecx movl –8(%ebp), %eax addl %eax, %ecx. Fault-handler hardware 1.Enters privileged mode 2.Sets EIP to specific location in operating system 3.Sets ESP to operating- system stack in OS memory 4.Pushes old (process 1) EIP and ESP on OS stack Process 1’s memory Registers PCB3 PCB2 PCB1 OS’s memory Running Waiting Process 1

28 Context Switch, in More Detail addl %eax, %ecx movl –8(%ebp), %eax addl %eax, %ecx. OS software 5.Pops saved EIP,ESP into PCB1 6.Copies rest of registers into PCB1 7.Sends instructions to disk drive to fetch page Process 1’s memory Registers PCB3 PCB2 PCB1 OS’s memory Running Waiting Process 1

29 Resuming Some Other Process Hardware 12.Pops EIP,ESP into registers 13.Switches back to unprivileged mode 14.Resumes where process 2 left off last time Process 1’s memory Registers PCB3 PCB2 PCB1 OS’s memory OS software 8.Sets process-ID register to 2 9.Pushes saved EIP,ESP from PCB2 onto OS stack 10.Copies rest of registers from PCB2 11.Executes “return from interrupt” instruction

30 System call, just another kind of fault Running Waiting Process 1 mov $4,%eax int $0x80 addl %eax, %ecx. system call (privileged instruction) PCB3 PCB2 PCB1 OS’s memory Process 1’s memory Registers

31 Summary Abstraction of a “process”  CPU: a share of CPU resources on a small time scale  Memory: a complete address space of your own OS support for the process abstraction  CPU: context switch between processes  Memory: virtual memory (VM) and page replacement  Files: open/read/write, rather than “move disk head”  Protection: ensure process access only its own resources Hardware support for the process abstraction  Context switches, and push/pop registers on the stack  Switch between privileged and unprivileged modes  Map VM address and process ID to physical memory