Download presentation
Presentation is loading. Please wait.
1
Implementing Processes, Threads, and Resources
2
Basic OS Functions Processor(s) Main Memory Devices Process, Thread &
Resource Manager Memory Manager Device File
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
Abstract Computing Environment
Process Manager – cont. Program Process Abstract Computing Environment File Manager Memory Device Protection Deadlock Synchronization Description CPU Other H/W Scheduler Resource Devices Process Mgr
7
Implementing the Process Abstraction
OS Address Space Control Unit OS interface … Machine Executable Memory ALU CPU Pi Address Pi CPU Pi Executable Memory Pk Address Pk CPU Pk Executable Pj Address Pj CPU Pj Executable
8
External View of the Process Manager
Hardware Application Program Device Mgr Process Mgr Memory Mgr File Mgr UNIX Windows CreateThread() CreateProcess() CloseHandle() WaitForSingleObject() fork() exec() wait()
9
Modern Processes and Threads
OS interface … Pi CPU Thrdj in Pi Thrdk in Pi
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
The Address Space Process Files Other objects Address Space Binding
Executable Memory Other objects Files
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
Tracing the Hardware Process
Bootstrap Loader Process Manager Interrupt Handler P1 P2 Pn … Machine is Powered up Initialization Load the kernel Service an interrupt Hardware process progress Execute a thread Schedule
18
The Abstract Machine Interface
User Mode Instructions Application Program Abstract Machine Instructions Trap Instruction Supervisor Mode fork() create() open() OS
19
Context Switching CPU New Thread Descriptor Old Thread Descriptor
20
Context Switching – cont.
Process Manager Interrupt Handler P1 P2 Pn Executable Memory Initialization 1 2 3 4 5 7 8 9 6
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
Creating a Process in UNIX
pid = fork(); UNIX kernel Process Table … Process Descriptor
23
Linux Process Descriptor
Execution of the collection of tasks - Managed by the Linux kernel Struct task_struct is created when a process is created and it is “tied” into the list of tasks
24
Linux Process Descriptor
*Process descriptor is stored in dynamic memory *Processes are dynamic entities whose lifetimes range from a few milliseconds to months. Thus, the kernel must be able to handle many processes at the same time, and process descriptors are stored in dynamic memory rather than in the memory area permanently assigned to the kernel.
25
Linux Process Descriptor
26
Windows NT Process Descriptor
EPROCESS … void *UniqueProcessId; NT Executive KPROCESS uint32 KernelTime; uint32 UserTime; Byte state; NT Kernel NT Kernel handles object management, interrupt handling, thread scheduling NT Executive handles all other aspect of a process
27
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
28
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
29
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.
30
Windows NT Thread Descriptor
ETHREAD EPROCESS KPROCESS NT Kernel KTHREAD NT Executive
31
Creating a Process in NT
CreateProcess(…); Win32 Subsystem ntCreateProcess(…); … ntCreateThread(…); NT Executive Handle Table NT Kernel … Process Descriptor
32
Windows NT Handles
33
Simple State Diagram Request Done Running Schedule Start Allocate
Ready Blocked Running Start Schedule Request Done Allocate
34
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
35
Windows NT Thread States
CreateThread Terminated Initialized Reinitialize Activate Dispatch Exit Wait Waiting Ready Running Wait Complete Wait Complete Select Preempt Transition Dispatch Standby
36
Resources Resource: Anything that a process can request, then be blocked because that thing is not available. Resource Descriptors - Internal resource name - Total Units - Available Units - List of available units - List of Blocked processes
37
Resources R = {Rj | 0 j < m} = resource types C = {cj 0 | for 0 j < m s.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.
38
Using the Model There is a resource manager, Mgr(Rj) for every Rj
pi can only request ni cj units of reusable Rj pi can request unbounded # of units of consumable Rj Process pi can request units of Rj if it is currently running Mgr(Rj) can allocate units of Rj to pi request Mgr(Rj) Process allocate
39
A Generic Resource Manager
Blocked Processes Policy Process request() Process release() Resource Pool
40
Process Hierarchies Initial Process System Other Process Processes
Some OS use this hierarchical relationship - while others simply ignore it.
41
Process Hierarchies Parent-child relationship may be significant: parent controls children’s execution Request Done Running Yield Suspend Request Schedule Suspend Start Ready-Active Activate Ready-Suspended Allocate Allocate Suspend Blocked-Active Blocked-Suspended Activate
42
Process Manager Overview
Program Process Abstract Computing Environment File Manager Memory Device Protection Deadlock Synchronization Description CPU Other H/W Scheduler Resource Devices Process Mgr
43
UNIX Organization Process Libraries Process Process
System Call Interface Deadlock Process Description File Manager Protection Synchronization Device Manager Memory Manager Resource Manager Scheduler Monolithic Kernel Devices Memory CPU Other H/W
44
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.