Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

Process Management

External View of the OS

wait()
close()
sleep()
File Mgr
fork()
signal()
Device Mgr
CC semctl()
Hardware
Program
Program SetWaitableTimer()
Memory Mgr
CreateProcess() Process Mgr
CreateThread()
CloseHandle()
OS
WaitForSingleObject()
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 synchronize 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 Kernel ISRs Process i Process j


BIOS

Program

Hardware
process

Switch to
another
program
Process Abstraction Layers
pi, pj, and pk each
Pi Pj Pk
have their own
Process Mgr Virt Term Virt Term Virt Term
virtual terminal
Window Mgr interface

Pi Pj Pk pi, pj, and pk each


Control Control Control have their own
Unit Unit Unit virtual machine
OS interface
OS
OS PPi
Address
Address Address
i
Hardware process
Address
Space
Space Space
Space (OS) coroutines across
pi, pj, and pk under OS
PPk
Control Address
k control
PPj Address
Unit Address
j Space
Space
Address
Space
Space
Process Manager Overview
Program
Program Process
Process
Process Mgr

Abstract Computing Environment

File Deadlock
Deadlock Process
Process
Manager Protection Description
Description
Protection
Synchronization
Synchronization
Device Memory Resource
Scheduler Resource
Resource
Manager Manager Scheduler Resource
Resource
Manager
Resource
Manager
Manager
Manager
Manager
Manager

Devices
Devices Memory
Memory CPU
CPU Other
OtherH/W
H/W
Unix Organization
Process Process
Process
Libraries Process
Libraries Process
Process

System
SystemCall
CallInterface
Interface
File Deadlock
Deadlock Process
Process
Manager Protection Description
Description
Protection
Synchronization
Synchronization
Device Memory Resource
Scheduler Resource
Resource
Resource
Manager Manager Scheduler Resource
Manager
Resource
Manager
Manager
Manager
Monolithic Kernel Manager
Manager

Devices
Devices Memory
Memory CPU
CPU Other
OtherH/W
H/W
NT Organization
Process T Process
Process
Process T T
T T T T
T Process
Process
T
Libraries
Libraries
Subsystem
Subsystem Subsystem
Subsystem Subsystem
Subsystem
User
Supervisor
NT Executive
NT Kernel I/O
I/OSubsystem
Subsystem
Hardware
HardwareAbstraction
AbstractionLayer
Layer

Processor(s) Main Memory 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
NT Executive
Kernel
Object

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)
request Mgr(Rj)

allocate
release

Process
Process
Resource Manager Design

Mgr(Rj)
request release

allocate
release
allocate

release
Process
Process
allocate
Resource Pool
Address Space

Primary
Primary
Memory
Memory

Address Space
Process
Process 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 Absolute Primary Memory


LinkEditor
Editor Program

Loader Executable
Loader Program
Address Space
AddressSpace
Map
Map

Map
Map
Processes &Threads

Resources
State

Stack
State

Static data

Program Stack
Process State (Version 1)
Request
Done
Running

Request Schedule

Allocate Start

Blocked Ready
Process State (UNIX)
Request
Wait by
parent Done
Running
zombie Schedule
Request
Sleeping I/O Request
Allocate
Start

Runnable
I/O Complete Resume

Uninterruptible Traced or Stopped


Sleep
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

You might also like