1 / 39

Implementing Processes, Threads, and Resources

Implementing Processes, Threads, and Resources. File Manager. Process, Thread & Resource Manager. Memory Manager. Device Manager. Processor(s). Main Memory. Devices. Basic OS Functions. What is a Process. Classic process (used up to late 80s/early 90s)

Download Presentation

Implementing Processes, Threads, and Resources

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. Implementing Processes,Threads, and Resources

  2. File Manager Process, Thread & Resource Manager Memory Manager Device Manager Processor(s) Main Memory Devices Basic OS Functions

  3. What is a Process • Classic process (used up to late 80s/early 90s) • Program in execution on a von Neumann computer • New abstraction divides aspects of classic process into two parts • Modern process: the part that defines a customized computational framework in which a program executes • Thread: the part that keeps track of code executions within this framework • Classic process = modern process with 1 thread

  4. Process Manager • Process manager creates the process abstraction • It implements a software environment for processes to run • Algorithms that define the behavior of the operating system • Data structures to preserve the state of the execution

  5. Process Manager – cont. • Define what “things” threads in the process can reference – the address space (most of the “things” are memory locations) • Manage the resources used by the processes/threads • Tools to create/destroy/manipulate processes & threads • Tools to time-multiplex the CPU – Scheduling (Chapter 7) • Tools to allow threads to synchronization the operation with one another (Chapters 8-9) • Mechanisms to handle deadlock (Chapter 10) • Mechanisms to handle protection (Chapter 14)

  6. Program Process Abstract Computing Environment Process Description File Manager Process Mgr Protection Deadlock Synchronization Device Manager Memory Manager Resource Manager Resource Manager Scheduler Resource Manager Devices Memory CPU Other H/W Process Manager – cont.

  7. Pi CPU Pj CPU Pk CPU … Pi Executable Memory Pj Executable Memory Pk Executable Memory OS interface OSAddress Space CPU ALU Pi Address Space Machine Executable Memory Pk Address Space Control Unit … Pj Address Space Implementing the Process Abstraction

  8. Application Program fork() CreateThread() CreateProcess() CloseHandle() wait() exec() WaitForSingleObject() Device Mgr Process Mgr Memory Mgr Device Mgr Process Mgr Memory Mgr File Mgr File Mgr UNIX Windows Hardware External View of the Process Manager

  9. Thrdj in Pi Thrdk in Pi … Pi CPU … … OS interface … Modern Processes and Threads

  10. Processes • A process is a sequential program in execution • The object program to be executed • The data on which the program will execute • Resources required by the program • The threads in the process • A host process environment • The status of each thread’s execution • Thread-specific data, such as a stack, a PC, and set of register values

  11. Process Address Space • Process address space • The collection of addresses a thread can reference • Normally refer to an executable memory location • Can refer to OS services and resources

  12. Executable Memory Address Space Address Binding Process Files Other objects The Address Space

  13. Building the Address Space • Some parts are built into the environment • Files • System services • Some parts are imported at runtime • Mailboxes • Network connections • Memory addresses are created at compile (and run) time

  14. Process Manager Responsibilities • Create process abstraction • Create thread abstraction • Process/thread synchronization • Create resource abstraction • Resource protection • Cooperation with device manager to implement I/O • Implementation of address space

  15. Modern Process Composed of: • Address space • Program to define behavior of process • Data used by process • Resources needed for thread execution • Process created with a minimal set of resources • Additional resources allocated as needed

  16. The Hardware Process • Hardware process refers to the iterative activity of the control unit • Repeatedly fetching and executing instructions

  17. Machine is Powered up Bootstrap Process Manager Interrupt Handler P1 P2 Pn Loader Load the kernel Initialization Execute a thread … Schedule Hardware process progress Service an interrupt Tracing the Hardware Process

  18. Application Program Abstract Machine Instructions Trap Instruction fork() User Mode Instructions open() create() OS User Mode Instructions Supervisor Mode Instructions The Abstract Machine Interface

  19. Old Thread Descriptor CPU New Thread Descriptor Context Switching

  20. Executable Memory 1 Initialization Process Manager 7 8 Interrupt Interrupt Handler 2 P1 3 4 9 P2 5 6 Pn Context Switching – cont.

  21. Process Descriptors • OS creates/manages process abstraction • Descriptor is data structure for each process • Register values • Logical state • Type & location of resources it holds • List of resources it needs • List of threads • List of child processes • Security keys • etc.

  22. EPROCESS KPROCESS … uint32 KernelTime; uint32 UserTime; … Byte state; NT Kernel NT Executive … void *UniqueProcessId; … Windows NT Process Descriptor

  23. Windows NT Process Descriptor – cont. • Kernel process object including: • Pointer to the page directory • Kernel & user time • Process base priority • Process state • List of the Kernel thread descriptors that are using this process

  24. Windows NT Process Descriptor – cont. • Parent identification • Exit status • Creation and termination times. • Memory status • Security information • executable image • Process priority class used by the thread scheduler. • A list of handles used by this process • A pointer to Win32-specific information

  25. Thread Abstraction • The major tasks in managing a thread include • Create/destroy a thread • Allocate thread-specific resources • Manage thread context switching • The thread descriptor is the data structure where the OS keeps all information to manage that thread • Current state, execution stats, reference to associated process, related threads, etc.

  26. ETHREAD EPROCESS KTHREAD KPROCESS NT Kernel NT Executive Windows NT Thread Descriptor

  27. Creating a Process in UNIX pid = fork(); UNIX kernel Process Table … Process Descriptor

  28. Creating a Process in NT CreateProcess(…); Win32 Subsystem ntCreateProcess(…); … ntCreateThread(…); NT Executive Handle Table NT Kernel … Process Descriptor

  29. Windows NT Handles

  30. Request Done Running Request Schedule Start Allocate Ready Blocked Simple State Diagram

  31. UNIX State Transition Diagram Request Wait by parent Done Running zombie Schedule Request Sleeping I/O Request Start Allocate Runnable I/O Complete Resume Traced or Stopped Uninterruptible Sleep

  32. Windows NT Thread States CreateThread Terminated Initialized Reinitialize Activate Dispatch Exit Wait Waiting Ready Running Wait Complete Wait Complete Preempt Select Transition Dispatch Standby

  33. Resources Resource: Anything that a process can request, then be blocked because that thing is not available. R = {Rj | 0  j < m} = resource types C = {cj 0 | for 0  j < ms.t. RjR} = units of Rj available Reusable resource: After a unit of the resource has been allocated, it must ultimately be released back to the system. E.g., CPU, primary memory, disk space, … The maximum value for cj is the number of units of that resource Consumable resource: There is no need to release a resource after it has been acquired. E.g., a message, input data, … Notice that cj is unbounded.

  34. Process pi can request units of Rj if it is currently running pi can only request ni cj units of reusable Rj pi can request unbounded # of units of consumable Rj • Mgr(Rj) can allocate units of Rj to pi request allocate Using the Model • There is a resource manager, Mgr(Rj) for every Rj Mgr(Rj) Process

  35. Process Process Process A Generic Resource Manager Resource Manager Blocked Processes Policy request() Process release() Resource Pool

  36. Process Hierarchies • Parent-child relationship may be significant: parent controls children’s execution Request Done Running Yield Suspend Request Schedule Start Suspend Ready-Active Activate Ready-Suspended Allocate Allocate Suspend Blocked-Active Blocked-Suspended Activate

  37. Program Process Abstract Computing Environment Process Description File Manager Process Mgr Protection Deadlock Synchronization Device Manager Memory Manager Resource Manager Resource Manager Scheduler Resource Manager Devices Memory CPU Other H/W Process Manager Overview

  38. Resource Manager Resource Manager Scheduler Resource Manager UNIX Organization Process Libraries Process Process System Call Interface Deadlock Process Description File Manager Protection Synchronization Device Manager Memory Manager Monolithic Kernel Devices Memory CPU Other H/W

  39. Windows NT Organization Process Process T T Process T T T T Libraries T T T Subsystem Subsystem Subsystem User I/O Subsystem NT Executive NT Kernel Hardware Abstraction Layer Processor(s) Main Memory Devices

More Related