Sie sind auf Seite 1von 34

Chapter 6

Implementing
Processes, Threads,
and Resources

Implementing the Process Abstraction


Pi CPU

Pj CPU

PPi Executable
i Executable
Memory
Memory

PPj Executable
j Executable
Memory
Memory

Pk CPU

PPk Executable
k Executable
Memory
Memory

CPU
ALU
Control
Unit

OS
OSAddress
Address
Space
Space
PPi Address
i Address
Space
Space
PPk Address
k Address
Space
Space

PPj Address
j Address
Space
Space

Machine Executable Memory

OS interface

External View of the Process Manager


Application
Application
Program
Program

Device Mgr

UNIX

Memory Mgr
File Mgr

exec()

Memory Mgr
File Mgr

Process Mgr

Device Mgr

wait()

CreateThread()
CloseHandle() CreateProcess()
WaitForSingleObject()

Process Mgr

fork()

Windows

Hardware

Process Manager 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)
Mechanisms to handle protection (Chapter 14)

Modern Processes and Threads


Thrdj in Pi

Thrdk in Pi

Pi CPU

OS interface

Map
Map
Program

Static data

Resources

AddressSpace
Space
Address

Stack

Stack

Processes &Threads
State

State

Map
Map

Process Address Space


Process address space is the collection of
addresses that a thread can reference.
Normally, it refers to an executable memory
location.
However, due to the nature of a process, a
process address space can also be
associated with other machine abstract
elements-such as, files, device registers and
other objects.

Memory-Mapped-Resources
1. Most of the components in a computer
system can be referenced by memory
addresses. (One of the exception is the
processor it self)
2. The address space provides a uniform
mechanism by which a process can
reference bytes in all memory-mapped
resources.
3. Each resource manager is responsible for
binding addresses with addressable
elements of the resource.

The Address Space


Address
Space

Process
Process

Address
Binding

Executable
Memory

Files

Other objects

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

Tracing the Hardware Process

Hardware process progress

Machine is
Powered up

Bootstap

Load the kernel


Initialization
Execute a thread
Schedule
Service an interrupt

Process Interrupt
Loader Manager Handler P1

P,2

Pn

Responsibilities of Process Manager

1. Process Creation and Termination


2. Thread Creation and Termination
3. Process/Thread Synchronization
4. Resource Allocation
5. Resource Protection
6. Co-operate with Device Manager to
Implement I/O
7. Co-operate with the Memory Manager to
Implement Memory Space

The Abstract Machine Interface


Application Program
Abstract Machine Instructions
Trap
Instruction
User Mode
Instructions

fork()
open()

OS

User
UserMode
Mode
Instructions
Instructions

Supervisor
SupervisorMode
Mode
Instructions
Instructions

create()

Context Switching-Abstract Machine switching


Executable Memory
Initialization
Interrupt

Process
Manager

Interrupt
Handler
2
4
9

P1
P2

Pn

OS Families-Example
POSIX Standard Description Release
POSIX.1-1988 system interfaces and headers

SunOS 4.1

POSIX.1-1990 POSIX.1-1988 update

Solaris 2.0

POSIX.1b-1993 real-time extensions

Solaris 2.4

POSIX.1c-1996 threads extensions

Solaris 2.6

POSIX.2-1992 shell and utilities

Solaris 2.5

POSIX.2a-1992 interactive shell and utilities

Solaris 2.5

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
Security keys
etc. (see Table 6.1 and the source code of your
favorite OS)

Windows NT Process Descriptor


EPROCESS
KPROCESS

NT Kernel

NT Executive

uint32
uint32

Byte

void

KernelTime;
UserTime;
state;

*UniqueProcessId;

Windows NT Process Descriptor (2)


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 (3)

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

Windows NT Thread Descriptor


EPROCESS
KPROCESS

ETHREAD
KTHREAD

NT Kernel
NT Executive

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

Windows NT Handles

Application
Handle
User Space
Supervisor Space
Executive Object
Kernel
Object

NT Executive

NT Kernel

Simple State Diagram


Request
Done

Running

Request

Schedule
Start

Allocate
Blocked

Ready

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

Windows NT Thread States


CreateThread

Initialized
Activate

Dispatch
Exit

Running

Wait

Waiting

Ready

Wait Complete

Wait Complete

Transition
Dispatch

Preempt

Reinitialize

Select

Terminated

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 | RjR (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

request

Mgr(Rj)

Process
Process
allocate

A Generic Resource Manager


Resource Manager
Policy

Blocked Processes
Process
Process
Process
Process
Process
Process

Process
Process

request()
release()

Resource Pool

Process Hierarchies
Parent-child relationship may be significant:
parent controls childrens execution
Done

Request
Running

Yield
Request
Ready-Active

Blocked-Active

Schedule
Suspend
Activate
Allocate
Suspend
Activate

Suspend
Start
Ready-Suspended
Allocate
Blocked-Suspended

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

Windows NT Organization
T

Process
Process
T

T
T

Process
Process

Process
Process

Libraries
Libraries
Subsystem
Subsystem

User

Subsystem
Subsystem

NT Executive
NT Kernel
Hardware
HardwareAbstraction
AbstractionLayer
Layer
Processor(s)

Main Memory

Subsystem
Subsystem

I/O
I/OSubsystem
Subsystem

Devices

Das könnte Ihnen auch gefallen