340 likes | 507 Views
Chapter 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
Chapter 6 Implementing Processes, Threads, and Resources
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 …
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
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)
Thrdj in Pi Thrdk in Pi … Modern Processes and Threads … Pi CPU … … OS interface
State Stack Stack Map Processes &Threads State Map Address Space Program Static data Resources
Process Address Space • Process address space is the collection of addresses that a thread can reference. • Normally, it refers to an executable memory location. • However, due to the nature of a process, a process address space can also be associated with other machine abstract elements-such as, files, device registers and other objects.
Memory-Mapped-Resources • 1. Most of the components in a computer system can be referenced by memory addresses. (One of the exception is the processor it self) • 2. The address space provides a uniform mechanism by which a process can reference bytes in all memory-mapped resources. • 3. Each resource manager is responsible for binding addresses with addressable elements of the resource.
Files Other objects The Address Space Executable Memory Address Space Address Binding Process
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
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
Responsibilities of Process Manager • 1. Process Creation and Termination • 2. Thread Creation and Termination • 3. Process/Thread Synchronization • 4. Resource Allocation • 5. Resource Protection • 6. Co-operate with Device Manager to Implement I/O • 7. Co-operate with the Memory Manager to Implement Memory Space
Trap Instruction fork() open() create() OS Supervisor Mode Instructions The Abstract Machine Interface Application Program Abstract Machine Instructions User Mode Instructions User Mode Instructions
1 Initialization 7 8 Interrupt 2 3 4 9 5 6 Context Switching-Abstract Machine switching Executable Memory Process Manager Interrupt Handler P1 P2 Pn
POSIX Standard Description Release POSIX.1-1988 system interfaces and headers SunOS 4.1 POSIX.1-1990 POSIX.1-1988 update Solaris 2.0 POSIX.1b-1993 real-time extensions Solaris 2.4 POSIX.1c-1996 threads extensions Solaris 2.6 POSIX.2-1992 shell and utilities Solaris 2.5 POSIX.2a-1992 interactive shell and utilities Solaris 2.5 • OS Families-Example
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)
EPROCESS NT Executive … void *UniqueProcessId; … Windows NT Process Descriptor KPROCESS … uint32 KernelTime; uint32 UserTime; … Byte state; NT Kernel
Windows NT Process Descriptor (2) • 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
Windows NT Process Descriptor (3) • 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
ETHREAD EPROCESS KPROCESS Windows NT Thread Descriptor KTHREAD NT Kernel NT Executive
Creating a Process in UNIX pid = fork(); UNIX kernel Process Table … Process Descriptor
Creating a Process in NT CreateProcess(…); Win32 Subsystem ntCreateProcess(…); … ntCreateThread(…); NT Executive Handle Table NT Kernel … Process Descriptor
Simple State Diagram Request Done Running Request Schedule Start Allocate Ready Blocked
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
Windows NT Thread States CreateThread Terminated Initialized Reinitialize Activate Dispatch Exit Wait Waiting Ready Running Wait Complete Wait Complete Preempt Select Transition Dispatch Standby
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.
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
Process Process Process A Generic Resource Manager Resource Manager Blocked Processes Policy request() Process release() Resource Pool
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
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
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
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