240 likes | 340 Views
6. Implementing Processes, Threads, and Resources. P i CPU. P j CPU. P k CPU. …. P i Executable Memory. P j Executable Memory. P k Executable Memory. P i Address Space. P k Address Space. P j Address Space. Implementing the Process Abstraction. OS interface.
E N D
6 Implementing Processes, Threads, and Resources Operating Systems: A Modern Perspective, Chapter 6
Pi CPU Pj CPU Pk CPU … Pi Executable Memory Pj Executable Memory Pk Executable Memory Pi Address Space Pk Address Space Pj Address Space Implementing the Process Abstraction OS interface OSAddress Space CPU ALU Machine Executable Memory Control Unit … Operating Systems: A Modern Perspective, Chapter 6
CreateThread() CreateProcess() CloseHandle() WaitForSingleObject() Device Mgr Process Mgr Memory Mgr File Mgr Windows External View of the Process Manager Application Program fork() wait() exec() Device Mgr Process Mgr Memory Mgr File Mgr UNIX Hardware Operating Systems: A Modern Perspective, Chapter 6
Process Manager Responsibilities • Define & implement the essential characteristics of a process and thread • Algorithms to define the behavior • Data structures to preserve the state of the execution • 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 the (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) Operating Systems: A Modern Perspective, Chapter 6
Thrdj in Pi Thrdk in Pi … Modern Processes and Threads … Pi CPU … … OS interface Operating Systems: A Modern Perspective, Chapter 6
State Stack Stack Map Processes &Threads State Map Address Space Program Static data Resources Operating Systems: A Modern Perspective, Chapter 6
Files Other objects The Address Space Executable Memory Address Space Address Binding Process Operating Systems: A Modern Perspective, Chapter 6
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 Operating Systems: A Modern Perspective, Chapter 6
Load the kernel Initialization Execute a thread Schedule Service an interrupt Tracing the Hardware Process Machine is Powered up Bootstap Process Manager Interrupt Handler P1 P,2 Pn Loader … Hardware process progress Operating Systems: A Modern Perspective, Chapter 6
Trap Instruction fork() open() create() OS Supervisor Mode Instructions The Abstract Machine Interface Application Program Abstract Machine Instructions User Mode Instructions User Mode Instructions Operating Systems: A Modern Perspective, Chapter 6
1 Initialization 7 8 Interrupt 2 3 4 9 5 6 Context Switching Executable Memory Process Manager Interrupt Handler P1 P2 Pn Operating Systems: A Modern Perspective, Chapter 6
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 • Security keys • etc. (see Table 6.1 and the source code of your favorite OS) Operating Systems: A Modern Perspective, Chapter 6
Creating a Process in UNIX pid = fork(); UNIX kernel Process Table … Process Descriptor Operating Systems: A Modern Perspective, Chapter 6
Simple State Diagram Request Done Running Request Schedule Start Allocate Ready Blocked Operating Systems: A Modern Perspective, Chapter 6
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 Operating Systems: A Modern Perspective, Chapter 6
Windows NT Thread States CreateThread Terminated Initialized Reinitialize Activate Dispatch Exit Wait Waiting Ready Running Wait Complete Wait Complete Preempt Select Transition Dispatch Standby Operating Systems: A Modern Perspective, Chapter 6
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 | RjR (0 j < m)} = 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. Operating Systems: A Modern Perspective, Chapter 6
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 Operating Systems: A Modern Perspective, Chapter 6
Process Process Process A Generic Resource Manager Resource Manager Blocked Processes Policy request() Process release() Resource Pool Operating Systems: A Modern Perspective, Chapter 6
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 Operating Systems: A Modern Perspective, Chapter 6
Resource Manager Resource Manager Scheduler Resource Manager Process Manager Overview Program Process Abstract Computing Environment Deadlock Process Description File Manager Protection Synchronization Device Manager Memory Manager Devices Memory CPU Other H/W Operating Systems: A Modern Perspective, Chapter 6
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 Operating Systems: A Modern Perspective, Chapter 6
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 Operating Systems: A Modern Perspective, Chapter 6