1 / 40

Operating Systems

Learn about the definition and management of processes and threads in operating systems, including process state transition, context switch, interrupt processing, interprocess communication, and threading models.

adkinsd
Download Presentation

Operating Systems

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. Operating Systems Operating Systems Unit 2: Process Context switch Interrupt Interprocess communication Thread Thread models

  2. Definition of Process • Set of steps • Performance of a task • A program in execution COP 5994 - Operating Systems

  3. Definition of Process • Process is • Identifiable Entity with properties • Text region • Stores the code that the processor executes • Data region • Stores variables and dynamically allocated memory • Stack region • Stores instructions and local variables for active procedure calls COP 5994 - Operating Systems

  4. Process State Transition Diagram end begin COP 5994 - Operating Systems

  5. … with Suspend and Resume COP 5994 - Operating Systems

  6. Process Management • OS functionality: • Create process • Dispatch process • Block/wakeup process • Suspend/resume process • Terminate process • Also: • Change process attributes • Enable Interprocess communication COP 5994 - Operating Systems

  7. Execution context Process Control Blocks COP 5994 - Operating Systems

  8. Context Switch • stop a running process and start a ready process • Save execution context of running process • Load ready process’s execution context COP 5994 - Operating Systems

  9. Context Switch COP 5994 - Operating Systems

  10. Context Switch • Switch must be transparent to process • Effort for switch must be minimized • hardware support: • Special PCB register to help save/restore • Processor is given PCB and perform switch without software intervention COP 5994 - Operating Systems

  11. Interrupt • Get attention of processor • enable reaction to signals from hardware • may be initiated by a running process: trap • E.g. dividing by zero or referencing protected memory • may be caused by external event • Asynchronous with the operation of the process • E.g., a keyboard key is pressed, or mouse is moved • Alternative: polling COP 5994 - Operating Systems

  12. Interrupt Processing • Processor is running a process • Interrupt occurs: current instruction is completed • Processor determines nature of interrupt • Process executes context switch to interrupt handler • Interrupt handler executes to completion • Next ready process is dispatched COP 5994 - Operating Systems

  13. Interrupt Processing COP 5994 - Operating Systems

  14. Interrupt Classes • Interrupts are system specific • IA-32 Pentium architecture: • Interrupts • Hardware: from devices external to a processor • Software: to enable system calls • Exceptions • error has occurred: hardware or software instruction • Terms: fault, trap or abort COP 5994 - Operating Systems

  15. IA32 Hardware Interrupt Classes COP 5994 - Operating Systems

  16. IA32 Exception Classes COP 5994 - Operating Systems

  17. Interprocess Communication • Process to process communication • Signal • Message COP 5994 - Operating Systems

  18. Signals • Software interrupts • Limited data exchange • Processes may catch, ignore or mask a signal • Catch: run specific function on signal • Ignore: let OS run default function • Mask: prevent signal from occurring COP 5994 - Operating Systems

  19. Message Passing • Send and receive functionality • Issues: • One directional • 1 sender, n receiver(s) • Blocking or non • Implementation: pipe or memory mapping • Security • Link reliability • Partner authentication COP 5994 - Operating Systems

  20. ? • Process is useful concept • to structure operating system • Also: for any complex software • Thread concept • Introduces two-level process concept COP 5994 - Operating Systems

  21. Motivation for Threads • Threads have become prominent in: • Software design • More naturally expresses inherently parallel tasks • Performance • Scales better to multiprocessor systems • Cooperation • Shared address space incurs less overhead than IPC COP 5994 - Operating Systems

  22. Thread definition • Lightweight process (LWP) • Thread of instructions or thread of control • Shares address space and other global information with its process • Registers, stack, signal masks and other thread-specific data are local to each thread COP 5994 - Operating Systems

  23. Thread vs. Process COP 5994 - Operating Systems

  24. Thread State Transition Diagram COP 5994 - Operating Systems

  25. Thread Operations • Thread and process share common operations • Thread specific operations: • Cancel • Signals thread to terminate: thread can mask the cancellation signal • Join • Thread joins another thread: allows a thread to sleep until joined thread ends COP 5994 - Operating Systems

  26. Threading Models • User-level threads • Kernel-level threads • Combination of user- and kernel-level threads COP 5994 - Operating Systems

  27. User-level Threads • Threading operations occur in user space • Threads are created by runtime libraries • Many-to-one mapping: • User sees multiple threads • OS sees one process COP 5994 - Operating Systems

  28. User-level Threads COP 5994 - Operating Systems

  29. User-level Threads • Many-to-one thread mapping • Advantage: User-level scheduling • performance tuning • avoids OS context switch • more portable • Disadvantage: one process for OS • All threads in process will block as a whole • Cannot be scheduled on multiple processors COP 5994 - Operating Systems

  30. Kernel-level Threads • Each thread has own execution • one-to-one mapping: • User and OS see multiple threads COP 5994 - Operating Systems

  31. Kernel-level Threads COP 5994 - Operating Systems

  32. Kernel-level Threads • one-to-one thread mapping • Advantage • Threads can run concurrently on multi processors: increased scalability and interactivity • Disadvantages: • context switching overhead • reduced portability COP 5994 - Operating Systems

  33. Combining User- and Kernel-level Threads m-to-n thread mapping: COP 5994 - Operating Systems

  34. Combining User- and Kernel-level Threads • Thread pool • Set of persistent worker kernel threads • Improves performance in environments where threads are frequently created and destroyed • Each new thread is executed by a worker thread COP 5994 - Operating Systems

  35. Combining User- and Kernel-level Threads • Scheduler activation • Meant to address limitations of user-level threads • Kernel thread block, blocks all user threads • Multiple user threads in kernel thread cannot execute concurrently on multi processor • Upcall: • OS calls a user-level threading library that determines if any of its threads need rescheduling COP 5994 - Operating Systems

  36. Thread Implementation Considerations • Signal delivery • Synchronous: • Occur as a direct result of program execution • Should be delivered to currently executing thread • Asynchronous • Occur due to an event typically unrelated to the current instruction • Threading library must determine each signal’s recipient so that asynchronous signals are delivered properly COP 5994 - Operating Systems

  37. Thread Signal Delivery COP 5994 - Operating Systems

  38. Example: UNIX Process COP 5994 - Operating Systems

  39. Example: Unix threads • POSIX Pthreads: • User level thread library • Linux threads: • Task: process and thread • Fork vs. Clone system call • specify which resources to share with the child thread COP 5994 - Operating Systems

  40. Agenda for next week: • Chapter 5 & 6 • Concurrency Issues • Read ahead ! COP 5994 - Operating Systems

More Related