1 / 143

主講人:虞台文

Operating Systems Principles Process Management and Coordination Lecture 4: The Operating System Kernel: Implementing Processes and Threads. 主講人:虞台文. Content. Kernel Definitions and Objects Queue Structures Threads Implementing Processes and Threads Process and Thread Descriptors

Download Presentation

主講人:虞台文

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 PrinciplesProcess Management and CoordinationLecture 4:The Operating System Kernel:Implementing Processes and Threads 主講人:虞台文

  2. Content • Kernel Definitions and Objects • Queue Structures • Threads • Implementing Processes and Threads • Process and Thread Descriptors • Implementing the Operations • Implementing Sync/Comm Mechanisms • Semaphores and Locks • Building Monitor Primitives • Clock and Time Management • Communications Kernel • Interrupt Handling

  3. Operating Systems PrinciplesProcess Management and CoordinationLecture 4:The Operating System Kernel:Implementing Processes and Threads Kernel Definitions and Objects

  4. Windows Kernel

  5. Windows Kernel Hardware dependent functions are placed in the kernel.

  6. OS Kernel • A basic set of objects, primitives, data structures, processes from which the remainder of the system may be built on its top. • In other words, the kernel transforms the hardware into an OS’s machine.

  7. OS’s Machine I am staying on the top of an OS machine.

  8. Kernel Objects • Kernel defines/provides mechanisms to implement various policies. • Four classes of possible functions and objects in a kernel: • Process and thread management • Interrupt and trap handling • Resource management • Input/output

  9. Process and thread management • Interrupt and trap handling • Resource management • Input/output Kernel Objects • Process and thread management • Process Creation • Process Destruction • Process Communication/Synchronization

  10. Process and thread management • Interrupt and trap handling • Resource management • Input/output Kernel Objects • Interrupt and trap handling • Responding to signals triggered by various system events. • Some system events: • Process termination • I/O completion • Time-out of clock • Error • Hardware malfunction

  11. CPU I/O Processor Done Interrupt • Process and thread management • Interrupt and trap handling • Resource management • Input/output Kernel Objects • Interrupt and trap handling • Responding to signals triggered by various system events. ...... ...... ...... ...... Do_I/O ...... Start I/O Interrupt Service Routine

  12. Process and thread management • Interrupt and trap handling • Resource management • Input/output Kernel Objects • Resource management • Primitives for maintaining, allocating, and releasing system resources. • Some system resources: • CPUs • Timers • Main memory • Secondary storage • I/O devices • Files

  13. Process and thread management • Interrupt and trap handling • Resource management • Input/output Kernel Objects • Input/output • Read, write, and control operations for initiating and supervising the transfer of data between I/O devices and main memory or registers.

  14. Main Topics in the Lecture • Process and thread management • Interrupt and trap handling • Resource management • Input/output Main topics

  15. p1 pj pn qm q1 child processes Process Creation Hierarchy Kernel ps OS process user 1 login user j login user n login user processes . . . . . . application processes. . . . Interaction with kernel objects

  16. Operating Systems PrinciplesProcess Management and CoordinationLecture 4:The Operating System Kernel:Implementing Processes and Threads Queue Structures

  17. Queues • OS needs many different queues • e.g., ready queues, wait queues. • Single-level queues • Implemented as array • Fixed size • Efficient for simple FIFO operations • Implemented as linked list • Unbounded size • More overhead, but more flexible operations

  18. Single-Level Queues Circular Array Implementation Link List Implementation

  19. Priority Queues Array indexed by priority

  20. Priority Queues Binary heap of priority

  21. Priority Queues Binary heap of priority Array implementation of binary heap

  22. Operating Systems PrinciplesProcess Management and CoordinationLecture 4:The Operating System Kernel:Implementing Processes and Threads Threads

  23. Lowest Address, e.g., 00000000 Highest Address, e.g., FFFFFFFF Virtual Memory Address Spaces Memory

  24. Lowest Address, e.g., 00000000 Starting Address of all processes Highest Address, e.g., FFFFFFFF Virtual Memory Address Spaces Memory OS User Programs

  25. OS OS OS OS User Programs Process 1 Process 2 Process n Only one process can be activated at a time. Each process thinks that it owns all memory. Processes Their address spaces are different.

  26. OS OS OS OS User Programs Process 1 Process 2 Process n Only one process can be activated at a time. Each process thinks that it owns all memory. Context Switching Context Switching Context Switching

  27. OS OS OS OS User Programs Process 1 Process 2 Process n Only one process can be activated at a time. Each process thinks that it owns all memory. Context Switching The context switching among processes, i.e., to change address space, is very time consuming.

  28. OS OS OS OS User Programs Process 1 Process 2 Process n Threads • Each process can have multiple threads. • They share the same address space. • The context switching among threads in the process is efficient. • Lightweight process  Mesa

  29. Processes and Threads

  30. Processes and Threads • Process has one or morethreads • All threads in a process share: • Memory space • Other resources • Each thread has its own: • CPU state(registers, program counter) • Stack • Threads are efficient, but lackprotection from each other

  31. Microsoft Windows Process & Thread Functions OS Support for Processes/Threads • Create a new Process/thread • Initiate or make a thread ready • Destroy or terminate a thread • Delay or put a thread to sleep for a given amount of time • Synchronize threads through semaphore, events, or condition variables • Perform lower-level operations, such as blocking, suspending, or scheduling a thread.

  32. Operating Systems PrinciplesProcess Management and CoordinationLecture 4:The Operating System Kernel:Implementing Processes and Threads Implementing Processes and Threads

  33. Process and Thread Descriptors • System needs some data structures to keep track the state and miscellaneous information, e.g., identification, resources used, accounting information, of processes and treads. • In the following, we are dealing with a system composed solely of processes, much of concept will also apply to threads.

  34. Process Control Block (PCB)

  35. Process Identification A system-wide unique identifier.

  36. State Vector

  37. CPU’s State Contain necessary data, e.g., program counter, data register, and flag register, to restart the process at the point of last interruption.

  38. Processor ID To identify the processor that is executing the process. Make sense only for multiprocessor system.

  39. Memory Memory map information. Physical Memory  Virtual Memory

  40. Status

  41. blocked running ready Point to the list, e.g., ready list or wait list, on which the process may reside. Status

  42. running Request Scheduler ready blocked Create Release More on Status • Basic process status • running, ready, and blocked • State transition diagram

  43. Suspend Thread Process Activation and Suspension Resume Thread • Some applications require a process (or thread) can be suspended by programs. • For examples • Suspension of a debugging program • Needed by the internal, e.g., to detect or prevent a deadlock.

  44. The Finer State Transition Diagram

  45. The Finer State Transition Diagram Active Processes Suspended Processes

  46. Creation Tree

  47. Creation Tree A link list of PCBs of the child processes Point to the PCB of the parent process.

  48. Priority Two methods: • Single-integer value • Two-leveled valued • Base priority + Changeable part Used by scheduler to decide which process should be running next.

  49. Priority Two methods: • Single-integer value • Two-leveled valued • Base priority + Changeable part Windows NT priority classes

  50. Others • CPU time used • Time remaining • Resource used • Resource claimed • Resource quotas • Number of I/O requests since creation • . . .

More Related