390 likes | 404 Views
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)
E N D
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) • 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
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
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)
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.
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
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
Thrdj in Pi Thrdk in Pi … Pi CPU … … OS interface … Modern Processes and Threads
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
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
Executable Memory Address Space Address Binding Process Files Other objects The Address Space
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
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
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
The Hardware Process • Hardware process refers to the iterative activity of the control unit • Repeatedly fetching and executing instructions
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
Application Program Abstract Machine Instructions Trap Instruction fork() User Mode Instructions open() create() OS User Mode Instructions Supervisor Mode Instructions The Abstract Machine Interface
Old Thread Descriptor CPU New Thread Descriptor Context Switching
Executable Memory 1 Initialization Process Manager 7 8 Interrupt Interrupt Handler 2 P1 3 4 9 P2 5 6 Pn Context Switching – cont.
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.
EPROCESS KPROCESS … uint32 KernelTime; uint32 UserTime; … Byte state; NT Kernel NT Executive … void *UniqueProcessId; … Windows NT Process Descriptor
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
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
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.
ETHREAD EPROCESS KTHREAD KPROCESS NT Kernel NT Executive Windows NT Thread Descriptor
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
Request Done Running Request Schedule Start Allocate Ready Blocked Simple State Diagram
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 | for 0 j < ms.t. RjR} = 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
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
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