IMPLEMENTING PROCESSES THREADS AND RESOURCES Basic OS Functions
IMPLEMENTING PROCESSES, THREADS, AND RESOURCES
Basic OS Functions File Manager Process, Thread & Resource Manager Processor(s) Memory Manager Device Manager Main Memory Devices 2
What is a Process � Classic process (used up to late 80 s/early 90 s) � 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 3
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 4
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) 5
Process Manager Program – cont. Process Abstract Computing Environment File Manager Devices Memory Manager Memory Process Protection Description Deadlock Synchronization Process Mgr Scheduler CPU Resource Manager Other H/W 6
Implementing the Process Abstraction Pi CPU Pj CPU Pi Executable Memory Pj Executable Memory Pk CPU … Pk Executable Memory CPU ALU Control Unit OS Address Space Pi Address Space Pk Address Space … Pj Address Space Machine Executable Memory OS interface 7
External View of the Process Manager Application Program UNIX Memory Mgr File Mgr Process Mgr exec() Memory Mgr File Mgr Process Mgr Device Mgr wait() Create. Thread() Close. Handle() Create. Process() Wait. For. Single. Object() Device Mgr fork() Windows Hardware 8
Modern Processes and Threads Thrdj in Pi Thrdk in Pi … Pi CPU … … OS interface … 9
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 10
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 11
The Address Space Address Binding Executable Memory Process Files Other objects 12
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 13
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 14
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 15
The Hardware Process � Hardware process refers to the iterative activity of the control unit � Repeatedly fetching and executing instructions 16
Tracing the Hardware Process Hardware process progress Machine is Powered up Bootstrap Load the kernel Initialization Execute a thread Schedule Service an interrupt Process Interrupt Loader Manager Handler P 1 P 2 Pn … 17
The Abstract Machine Interface Application Program Abstract Machine Instructions Trap Instruction User Mode Instructions fork() open() create() OS User Mode Instructions Supervisor Mode Instructions 18
Context Switching Old Thread Descriptor CPU New Thread Descriptor 19
Context Switching – cont. Executable Memory Initialization Interrupt 1 Process Manager 7 Interrupt Handler 2 4 9 8 3 P 1 P 2 5 6 Pn 20
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. 21
Windows NT Process Descriptor EPROCESS KPROCESS NT Kernel NT Executive … uint 32 … Byte … void … Kernel. Time; User. Time; state; *Unique. Process. Id; 22
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 23
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 Win 32 -specific information 24
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. 25
Windows NT Thread Descriptor EPROCESS KPROCESS ETHREAD KTHREAD NT Kernel NT Executive 26
Creating a Process in UNIX pid = fork(); UNIX kernel Process Table … Process Descriptor 27
Creating a Process in NT Create. Process(…); Win 32 Subsystem nt. Create. Process(…); … nt. Create. Thread(…); NT Executive Handle Table NT Kernel … Process Descriptor 28
Windows NT Handles 29
Simple State Diagram Request Done Running Request Schedule Start Allocate Blocked Ready 30
UNIX State Transition Diagram Request Wait by parent zombie Sleeping Done Running Schedule Request I/O Request Start Allocate Runnable I/O Complete Uninterruptible Sleep Resume Traced or Stopped 31
Windows NT Thread States Create. Thread Initialized Activate Dispatch Exit Running Waiting Ready Wait Complete Transition Dispatch Preempt Reinitialize Select Terminated Standby 32
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 < m s. 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. 33
Using the Model • There is a resource manager, Mgr(Rj) for every Rj • 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 Mgr(Rj) Process allocate 34
A Generic Resource Manager Policy Blocked Processes Process request() release() Resource Pool 35
Process Hierarchies • Parent-child relationship may be significant: parent controls children’s execution Done Request Running Yield Request Ready-Active Blocked-Active Schedule Suspend Activate Allocate Suspend Activate Suspend Start Ready-Suspended Allocate Blocked-Suspended 36
Process Manager Overview Program Process Abstract Computing Environment File Manager Devices Memory Manager Memory Process Protection Description Deadlock Synchronization Process Mgr Scheduler CPU Resource Manager Other H/W 37
UNIX Organization Process Libraries Process File Manager System Call Interface Deadlock Protection Process Description Synchronization Device Manager Memory Manager Scheduler Monolithic Kernel Devices Memory CPU Resource Manager Other H/W 38
Windows NT Organization T Process T T Libraries Subsystem User Subsystem NT Executive NT Kernel Hardware Abstraction Layer Processor(s) Main Memory Subsystem I/O Subsystem Devices 39
- Slides: 39