Process Management
26 Slides162.00 KB
Process Management
External View of the OS wait() close() sleep() fork() CC Program Program signal() semctl() File Mgr Device Mgr Memory Mgr SetWaitableTimer() CreateProcess() CreateThread() CloseHandle() WaitForSingleObject() Process Mgr OS Hardware
Process Management 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)
Initializing the Machine Power up fetch-execute cycle begins Initial (or hardware) process begins to run Executes ROM diagnostic program Then bootstrap loads the OS OS initialization – Setup & initialize all system data structures (this creates process & resource abstractions) – Initialize all devices – Start daemons – including idle process – Branches to the scheduler
Hardware Process Starts Idle Process BIOS Program Hardware process Switch to another program Kernel ISRs Process i Process j
Process Mgr Process Abstraction Layers Pi Virt Term Pj Virt Term Pk Virt Term pi, pj, and pk each have their own virtual terminal Pk Control Unit pi, pj, and pk each have their own virtual machine Window Mgr interface Pi Control Unit Pj Control Unit OS interface OS OS Address Address Space Space Control Unit PPi i Address Address Space Space PPj j Address Address Space Space PPk k Address Address Space Space Hardware process (OS) coroutines across pi, pj, and pk under OS control
Process Mgr Process Manager Overview Program Program Process Process Abstract Computing Environment File Manager Process Deadlock Process Deadlock Description Description Protection Protection Synchronization Synchronization Device Manager Devices Devices Memory Manager Memory Memory Scheduler Scheduler CPU CPU Resource Resource Resource Resource Resource Manager Resource Manager Manager Manager Manager Manager Other OtherH/W H/W
Unix Organization Libraries Libraries Process Process Process Process Process Process System SystemCall CallInterface Interface Process Deadlock File Process Deadlock Description Manager Description Protection Protection Synchronization Synchronization Device Memory Resource Resource Resource Scheduler Resource Manager Manager Scheduler Resource Manager Resource Manager Manager Manager Manager Manager Monolithic Kernel Devices Devices Memory Memory CPU CPU Other OtherH/W H/W
NT Organization T T Process Process T T T Process Process Process Process T T T T Libraries Libraries Subsystem Subsystem User Subsystem Subsystem Subsystem Subsystem Supervisor NT Executive NT Kernel Hardware HardwareAbstraction AbstractionLayer Layer Processor(s) Main Memory I/O I/OSubsystem Subsystem Devices
Process Descriptor 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)
Creating a Process in UNIX pid fork(); UNIX UNIXkernel kernel Process Table Process Descriptor
Creating a Process in NT CreateProcess( ); Win32 Win32Subsystem Subsystem ntCreateProcess( ); ntCreateThread( ); NT NTExecutive Executive Handle Table NT NTKernel Kernel Process Descriptor
Handles Application Handle User Space Supervisor Space Executive Object Kernel Object NT Executive NT Kernel
NT Process Descriptor User Space Supervisor Space NT Executive EPROCESS ETHREAD NT Kernel KPROCESS (PCB) KTHREAD
NT Process Descriptor 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
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
Resource Model 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 Rj R (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.
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 pi can release units of Rj that it holds (reusable) or produces (consumable) Mgr(Rj) request allocate release Process Process
Resource Manager Design release allocate Process Process allocate request release Mgr(Rj) release allocate Resource Pool
Address Space Process Process Address Space Primary Primary Memory Memory Mailboxes Files System services Other objects
Defining 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
The Compile Time Component Source Modules Translator Translator Relocatable Modules Link LinkEditor Editor Absolute Program Primary Memory Loader Loader Executable Program
Map Map Program Static data Resources AddressSpace Space Address Stack Stack Processes &Threads State State Map Map
Process State (Version 1) Request Done Running Request Schedule Start Allocate Blocked Ready
Process State (UNIX) 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
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