1 / 22

PROCESSES

PROCESSES. Concurrency and Process. What is concurrency? Process concurrency Decompose complex problems into simple ones The result: pseudoparallelism How do you check what processes are currently running at the computer?. Process Parallelism. Virtualization I/O parallelism

karlyn
Télécharger la présentation

PROCESSES

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PROCESSES

  2. Concurrency and Process • What is concurrency? • Process concurrency • Decompose complex problems into simple ones • The result: pseudoparallelism • How do you check what processes are currently running at the computer?

  3. Process Parallelism • Virtualization • I/O parallelism • CPU parallelism

  4. More on Process Parallelism • Process parallelism is common in real life • Each sales person sell $1M annually • Hire 100 sales people to generate $100M • Speedup • Ideal speedup is ? • Reality ? • Question: • Can you speed up by working with a partner? • Can you speed up by working with 20 partners? • Can you get super-linear (factor of N or more) speedup?

  5. Process • What is a process?

  6. Simplest Process • Sequential execution • Process state • Registers • Main memory • I/O devices • File system • Communication ports

  7. Program • What is a program? • What does a program consists of? • A process is an executing program

  8. Program and Process

  9. Process vs. Program • Process > program • Process < program

  10. Process Control Block (PCB) • Process management info • State • Ready: ready to run • Running: currently running • Blocked: waiting for resources (e.g., I/O) • Registers (including PC), CPU accounting info, etc. • Parent, etc. • Memory management info • Segments, page table, stats, etc. • I/O and file management • Communication ports, directories, file descriptors, etc. • How OS takes care of processes • Resource allocation and process state transition

  11. Process Data Structure • OS represents a process using a PCB • Has all the details about the process

  12. Process State Transition

  13. Primitives of Processes • Creation and termination • Signals • Operations • Synchronization

  14. When is a Process Created? • At system initialization: • When OS is booted  daemon processes • A running process might create a child process • A user request to create a new process • In user-interactive systems • Initiation of a batch system

  15. Make a Process • Creation • Load code and data into memory • Create an empty call stack • Initialize state to same as after a process switch • Make the process ready to run • Clone • Stop current process and save state • Make copy of current code, data, stack and OS state • Make the process ready to run

  16. Example: Unix • How to make processes: • Fork clones a process • Exec overlays the current process if ((pid = fork()) == 0) { /* child process */ exec(“foo”); /* does not return */ else /* parent */ wait(pid); /* wait for child to die */

  17. Shared Memory: for Efficiency • fork() actually shares memory between parent, child! • But if a page is modified, by either, fork duplicates it • Called “copy on write” sharing • Also shares open files, pipes, even stack and registers • In fact, duplicates everything except the fork() return value • If you call exec() this page-level sharing ends • Unix (Linux) and Windows also provide system calls to let processes share memory by “mapping” a file into memory • You tell it where, or let it pick an address range • Mapped files are limited to one writer. Can have many readers

  18. Fork() Creates Parallelism • Initially, child is a clone of parent except for “pid” • Even share file descriptors for files parent had open! • Linux: includes stdin, stdout, stderr • Plus files the parent explicitly opened. • Confusing: these shared files have a single “seek pointer”. If parent and child both do I/O, they “contend” for access.

  19. Process Termination • Exit: normal exit. What does it mean? • Abort: forced exit. Why?

  20. Process Context Switch • For a running process • All registers are loaded in CPU and modified • E.g. • When process relinquishes the CPU, the OS • Saves register values to the PCB of that process • To execute another process, the OS • Loads register values from PCB of that process • Context Switch • Process of switching CPU from one process to another • Very machine dependent for types of registers

  21. Details of Context Switching • Very tricky to implement • OS must save state without changing state • Should run without touching any registers • CISC: single instruction saves all state • RISC: reserve registers for kernel • Or way to save a register and then continue • Overheads: CPU is idle during a context switch • Explicit: • Direct cost of loading/storing registers to/from main memory • Implicit: • Opportunity cost of flushing useful caches (cache, TLB, etc.) • Wait for pipeline to drain in pipelined processors

  22. Context Switching is Costly! • In systems that do excessive amounts of context switching, it balloons into a big overhead • This is often ignored by application developers • But if you split an application into multiple processes need to keep it in mind • Make sure that each process does big chunks of work • Think about conditions under which context switching could occur and make sure they are reasonably rare

More Related