from program to process
play

From Program to Process To make the program s code and data come - PowerPoint PPT Presentation

From Program to Process To make the program s code and data come alive need a CPU The Process need memory the process address space for data, code, stack, heap A running program need registers PC, SP, regular registers need access to


  1. From Program to Process To make the program’ s code and data come alive need a CPU The Process need memory — the process’ address space for data, code, stack, heap A running program need registers PC, SP, regular registers need access to I/O list of open files How the OS Keeps Track A First Cut at the API of a Process Process Control Create A process has code Block causes the OS to create a new process OS must track program counter PC Stack Ptr Destroy Registers A process has a stack PID UID forcefully terminates a process OS must track stack pointer Priority List of open files Wait (for the process to end) Process status OS stores state of process Kernel stack ptr … Other controls in Process Control Block (PCB) e.g. to suspend or resume the process Data (program instructions, stack & heap) resides in memory, metadata is in PCB Status running? suspended? blocked? for how long?

  2. You’ll Never Walk Alone You’ll Never Walk Alone Machines run (and thus OS must manage) Machines run (and thus OS must manage) multiple processes multiple processes how should the machine’ s resources be mapped how should the machine’ s resources be mapped to these processes? to these processes? OS as a referee… Enter the illusionist! give every process the illusion of running } Virtualize on a private CPU the CPU which appears slower than the machine’ s give every process the illusion of running } Virtualize on a private memory memory which may appear larger(??) than the machine’ s Isolating Applications Mechanism and Policy Buggy apps can crash Mechanism other apps what the system can do App 1 App 2 App 3 Buggy apps can crash OS Policy Buggy apps can hog all what the system should do resources Operating System Malicious apps can violate Mechanisms should not determine policies! Reading and writing memory, privacy of other apps managing resources, accessing I/O... Malicious apps can change the OS

  3. The Process, Refined The Process, Refined An abstraction for isolation An abstraction for isolation the execution of an application the execution of an application App 1 program with restricted rights App 1 program with restricted rights The enforcing mechanism The enforcing mechanism must not hinder functionality must not hinder functionality OS OS still efficient use of hardware still efficient use of hardware Hardware Hardware enable safe communication enable safe communication How can the OS Special Enforce Restricted Rights? The process abstraction is enforced by the kernel Easy: kernel interprets each instruction! all kernel is in the OS slow not all the OS is in the kernel App 1 many instructions are safe: (why not? robustness) do we really need to involve the OS? widgets libraries, window managers etc OS Hardware

  4. How can the OS Amongst our weaponry are enforce restricted rights? such diverse elements as… Mechanism: Dual Mode Operation Privileged instructions in user mode, no way to execute potentially unsafe hardware to the rescue: use a instructions mode bit Memory isolation App 1 in user mode, processor checks in user mode, memory accesses outside a process’ every instruction memory region are prohibited in kernel mode, unrestricted rights Timer interrupts OS hardware to the rescue (again) Hardware kernel must be able to periodically regain control from to make checks efficient running process I. Privileged instructions I. Privileged instructions Set mode bit But how can an app do I/O then? system calls achieve access to kernel mode I/O ops only at specific locations specified by OS Memory management ops Executing a privileged instruction while in user mode (naughty naughty…) causes a Disable interrupts processor exception…. Set timers ...which passes control to the kernel Halt the processor

  5. II. Memory Protection Crossing the line user process mode bit = 1 Step 1: Virtualize Memory user process executing calls system call return from system call Virtual address space: set of memory mapped segments addresses that process can “touch” DLL s ’ trap mode bit := 1 CPU works with virtual addresses Stack mode bit := 0 return Physical address space: set of memory addresses supported by hardware kernel mode bit = 0 Heap execute system call Virtual Initialized data address space Code II. Memory Isolation Isolation Step 2: Address Translation At all times, functions used by different processes map to disjoint ranges — aka “Stay in your room!” Implement a function mapping into ⟨ pid, virtual address ⟩ physical address p i Virtual Physical p i Advantages: a486d9 p j isolation relocation 5e3a07 data sharing multiplexing

  6. Relocation Relocation The range of the function used by a process The range of the function used by a process can change over time can change over time — “Move to a new room!” p i p i Data Sharing Multiplexing Create illusion of almost infinite memory by Map different virtual addresses of distinct changing domain (set of virtual addresses) that processes to the same physical address — maps to a given range of physical addresses — “Share the kitchen!” ever lived in a studio? p i p i 04d26a 5e3a07 p j 119af3

  7. Multiplexing Multiplexing The domain (set of virtual addresses) that map The domain (set of virtual addresses) that map to a given range of physical addresses can to a given range of physical addresses can change over time change over time p i p i Multiplexing Multiplexing The domain (set of virtual addresses) that map The domain (set of virtual addresses) that map to a given range of physical addresses can to a given range of physical addresses can change over time change over time p i p i

  8. More Multiplexing More Multiplexing At different times, different processes can map At different times, different processes can map part of their virtual address space into the part of their virtual address space into the same physical memory — change tenants! same physical memory — change tenants! p i p i p j p j A simple mapping mechanism: On Base & Limit Base & Bound MAX sys Contiguous Allocation: contiguous virtual Memory addresses are mapped to contiguous physical Exception addresses Logical Physical no Isolation is easy, but sharing is hard 1500 addresses addresses p’ s physical CPU ≤ + Two copies of emacs: want to share code, but address yes space have heap and stack distinct... 1000 And there is more… 500 1000 Hard to relocate Bound Base Hard to account for dynamic changes in both Register Register 0 heap and stack

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend