操作系統(tǒng)-第2章-進(jìn)程與線程_第1頁(yè)
操作系統(tǒng)-第2章-進(jìn)程與線程_第2頁(yè)
操作系統(tǒng)-第2章-進(jìn)程與線程_第3頁(yè)
操作系統(tǒng)-第2章-進(jìn)程與線程_第4頁(yè)
操作系統(tǒng)-第2章-進(jìn)程與線程_第5頁(yè)
已閱讀5頁(yè),還剩217頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

操作系統(tǒng)

第二章進(jìn)程與線程

內(nèi)容

基礎(chǔ):進(jìn)程描述及控制

■■避免:死鎖與饑餓

??解決:幾個(gè)經(jīng)典問(wèn)題

■關(guān)于:進(jìn)程通信

。策略:進(jìn)程調(diào)度

2

62.1ProcessDescriptionand

Control

Learningobjectiv

BytheendofthisIcctureyoushouIdbeabIcto

?ExpIainwhat5sProcess,SwappingandThread

?掌握分析進(jìn)程的結(jié)構(gòu),PCB,Processimage(進(jìn)程映像)

?描述進(jìn)程的基本狀態(tài)及轉(zhuǎn)換規(guī)則與原因

?區(qū)別進(jìn)程的掛起與阻塞狀態(tài)

?理解OS內(nèi)核的主要功能

?理解ProcessControIPrimitives(原語(yǔ))

?區(qū)別ProcessSwitchingvs.ModeSwitching

?區(qū)別Processvs.Thread

MajorRequirementsofanOperating

System

?InterleavetheexecutionofseveraprocessestomaximizeprocessorutiIization

whiIeprovidingreasonabIeresponsetime

?AIlocateresourcestoprocesses

?Supportinterprocesscommunicationandusercreationofprocesses

程序的執(zhí)行順序

?程序順序執(zhí)行

■程序順序執(zhí)行時(shí)的特征:順序性、封閉性、可再現(xiàn)性

?程序并發(fā)執(zhí)行

■程序并發(fā)執(zhí)行時(shí)的特征:間斷性、非封閉性、不可再現(xiàn)性

?程序并發(fā)執(zhí)行條件(Bernstein條件)

■R(P1)nW(P2)UW(P1)HR(P2)UW(P1)HW(P2)={}

Process

?Alsocalledatask

?ExecutionofanindividuaIprogram

■進(jìn)程是程序在一個(gè)數(shù)據(jù)集合上的運(yùn)行過(guò)程,是系統(tǒng)進(jìn)行資源分配和調(diào)度的

一個(gè)獨(dú)立單位

■進(jìn)程是可并發(fā)執(zhí)行的程序在一個(gè)數(shù)據(jù)集合上的運(yùn)行過(guò)程

?Canbetraced

■Iistthesequenceofinstructionsthatexecute

CharacteristicsofProcess

?Dynamic(動(dòng)態(tài)性)

?Concurrency(并發(fā)性)

?Independent(獨(dú)立性)

?Asynchronous(異步性)

ProcessStructure

?Programs

?Datas

?PCB(ProcessControIBlock進(jìn)程控制塊)

第8-9講進(jìn)程狀態(tài)轉(zhuǎn)換

ProcessStates

?進(jìn)程的并發(fā)執(zhí)行

?進(jìn)程的2狀態(tài)

?進(jìn)程的5狀態(tài)

?進(jìn)程狀態(tài)轉(zhuǎn)換圖

假設(shè)內(nèi)存中有3個(gè)逆程A、B、C,他們的程序代碼已全部裝入內(nèi)存。若A、

C兩進(jìn)程需要執(zhí)行12條指令,B進(jìn)程需要執(zhí)行4條指令,且B進(jìn)程執(zhí)行到第

4條指令處必須等待I/Oo如何跟蹤他們的執(zhí)行過(guò)程?

Figure3.1Snapshot<jfExampleExecution(Figure3」

ntlitslrixrtkmCyck13

Dispatcher

?操作系統(tǒng)重要組件

?負(fù)責(zé)進(jìn)程、線程、作業(yè)的調(diào)度與分配

?提供多種調(diào)度算法如先來(lái)先服務(wù)、短作業(yè)優(yōu)先、時(shí)間片輪轉(zhuǎn)等

?監(jiān)測(cè)性能變化,如CPU使用率、10響應(yīng)時(shí)間等

?Tiiheau

4|too

-1/0requ4ftlot

42。

io2

440log3

"e

47”

"溜

?

5|12010

521201

33C??M?4InnefPrw(?“e?fflgw*3al

Two-StateProcessModeI

?Processmaybeinoneoftwostates

■Running(執(zhí)行)

■Not-running(非執(zhí)行)

Dispatch

Pause

(a)Statetransitiondl曄ram

Not-RunningProcessinaQueue

注:

?并非所有進(jìn)程只要Not-running就處于ready(就緒),有的需要blocked(阻塞)等待I/O完成

?Not-running又可分為ready和blocked兩種狀態(tài)

AFive-StateModeI

?Running(運(yùn)行)

?Ready(就緒)

?Blocked(阻塞)

?New(創(chuàng)建)

?Exit(終止)

?Running:占用處理機(jī)(單處理機(jī)環(huán)境中,某一時(shí)刻僅一個(gè)進(jìn)程占用處理機(jī))

?Ready:準(zhǔn)備執(zhí)行

?Blocked:等待某事件發(fā)生才能執(zhí)行,如等待I/O完成等

?New:進(jìn)程已經(jīng)創(chuàng)建,但未被OS接納為可執(zhí)行進(jìn)程

?Exit:因停止或取消,被OS從執(zhí)行狀態(tài)釋放

Admit

Fivure36Five-StateProcessModel

?NulIfNew:新創(chuàng)建進(jìn)程首先處于新狀態(tài)

?NewfReady:OS接納新狀態(tài)進(jìn)程為就緒進(jìn)程

?Ready->Running:OS只能從就緒進(jìn)程中選一個(gè)進(jìn)程

執(zhí)行

?RunningExit:執(zhí)行狀態(tài)的進(jìn)程執(zhí)行完畢,或被取

消,則轉(zhuǎn)換為退出狀態(tài)

?Running->Ready:分時(shí)系統(tǒng)中,時(shí)間片用完,或優(yōu)

先級(jí)高的進(jìn)程到來(lái),將終止優(yōu)先級(jí)低的進(jìn)程的執(zhí)行

?Running6Blocked:執(zhí)行進(jìn)程需要等待某事件發(fā)生。

通常因進(jìn)程需要的系統(tǒng)調(diào)用不能立即完成,而阻塞

?Blocked-Ready:當(dāng)阻塞進(jìn)程等待的事件發(fā)生,就

轉(zhuǎn)換為就緒狀態(tài)

?Ready.Exit:某些系統(tǒng)允許父進(jìn)程在任何情況下終

止其子進(jìn)程。若一個(gè)父進(jìn)程終止,其子孫進(jìn)程都必須終

止。

?BlockedExit:同前

ProwM.A

Fi?ure3.6ProcessStatesforTrace<>fFi13J

UsingTwoQueues

Krnd,QIM-IM*

AdmitDh|Mtch

PFIKYWH-

Tlnw<Mit

E*ent1Queue

Kvcnl!Event1Wall

Occurs

E、cnt2Queue

Ewnl2Event2Wall

Occur.

E、cnl”Queue

>>cntn?cnlnWalt

Occurs

<blMuldnleblockedciueiws

Swapping(對(duì)換技術(shù),交換技術(shù))

將內(nèi)存中暫時(shí)不能運(yùn)行的進(jìn)程,或暫時(shí)不用的數(shù)據(jù)和程序,Swapping-out到

外存,以騰出足夠的內(nèi)存空間,把已具備運(yùn)行條件的進(jìn)程,或進(jìn)程所需要的數(shù)

據(jù)和程序,Swapping-in內(nèi)存。

Swapping(對(duì)換技術(shù),交換技術(shù))

note

應(yīng)該保證進(jìn)程執(zhí)行時(shí)間比交換時(shí)間長(zhǎng)

交換空間通常作為磁盤的一整塊,且獨(dú)立于文件系統(tǒng)

普通的交換技術(shù)一般很少使用,交換技術(shù)的一些變體任然在UNIX等系統(tǒng)中使用

SuspendedProcesses

?ProcessorisfasterthanI/OsoaIIprocessescouIdbe

waitingforI/O

?Swaptheseprocessestodisktofreeupmorememory

?Blockedstatebecomessuspendstatev/henswappedtodisk

ReasonsforProcessSuspension

SwappingTheoperatingsystemneedstoreleasesufficientmain

memorytobringinaprocessthatisreadytoexecute

OtherOSreasonTheoperatingsystemmaysuspendabackgroundorutility

processoraprocessthatissuspectedofcausingaproblem

InteractiveuserrequestAusermaywishtosuspendexecutionofaprogramfor

purposesofdebuggingorinconnectionwiththeuseofa

resource

TimingAprocessmaybeexecutedperiodically(eg.an

accountingorsystemmonitoringprocess)andmaybe

suspendedwhilewaitingforthenexttimeinterval

ParentprocessrequestAparentprocessmaywishtosuspendexecutionofa

descendenttoexamineormodifythesuspendedprocess,or

tocoordinatetheactivityofvariousdescendents

被掛起進(jìn)程的特征

?不能立即執(zhí)行

?可能是等待某事件發(fā)生。若是,則阻塞條件獨(dú)立于掛起條件,即使

阻塞事件發(fā)生,該進(jìn)程也不能執(zhí)行

?使之掛起的進(jìn)程為:自身、其父進(jìn)程、OS

?只有掛起它的進(jìn)程才能使之由掛起狀態(tài)轉(zhuǎn)換為其他狀態(tài)

Suspendvs.BIocked(掛起與阻塞)

問(wèn)題

1?是否只能掛起阻塞進(jìn)程?

2?如何激活一個(gè)掛起進(jìn)程?

Suspenvs.BIocked

d區(qū)分兩個(gè)概念:

??進(jìn)程是否等待事件,阻塞與否

?進(jìn)程是否被換出內(nèi)存,掛起與否

4種狀態(tài)組合:

?Ready:進(jìn)程在內(nèi)存,準(zhǔn)備執(zhí)行

Blocked:進(jìn)程在內(nèi)存,等待事件

Ready,Suspend:進(jìn)程在外存,只要調(diào)入內(nèi)存

即可執(zhí)行

Blocked,Suspend:進(jìn)程在外存,等待事件

注:

處理機(jī)可調(diào)度執(zhí)行的進(jìn)程有兩種:

?新創(chuàng)建的進(jìn)程

?或換入一個(gè)以前掛起的進(jìn)程

通常為避免增加系統(tǒng)負(fù)載,系統(tǒng)會(huì)換入一個(gè)以前掛起的進(jìn)程執(zhí)行。

OneSuspendState

Admit

NewReady

Suspend

SuspendBlocked

此方案存在問(wèn)題!

Twonewstates

—Blocked,suspend

—Ready,suspend

TwoSuspendStates

Acthate

Blnckd/

BUI

Stipend

(b)WithTwoSuspendStates

具有掛起狀態(tài)的進(jìn)程狀態(tài)轉(zhuǎn)換

?BlockedBlocked.Suspend:OS通常將阻塞進(jìn)程換出,

以騰出內(nèi)存空間

?BIocked,Suspend.Ready,Suspend:當(dāng)BIocked,

Suspend進(jìn)程等待的事件發(fā)生時(shí),可以將其轉(zhuǎn)換為Ready,

Suspend

?Ready,SuspendReady:OS需要調(diào)入一個(gè)進(jìn)程執(zhí)行時(shí)

?ReadyReady,Suspend:一般,OS掛起阻塞進(jìn)程。但有

時(shí)也會(huì)掛起就緒進(jìn)程,釋放足夠的內(nèi)存空間

?NewReady,Suspend(NewReady):新進(jìn)程創(chuàng)建后,可

以插入到Ready隊(duì)列或Ready,Suspend隊(duì)列。若無(wú)足夠的內(nèi)

存分配給新進(jìn)程,則需要NewReady,Suspend

具有掛起狀態(tài)的進(jìn)程狀態(tài)轉(zhuǎn)換(續(xù))

?Blocked,SuspendBlocked:當(dāng)BIocked,Suspend隊(duì)列中有一個(gè)進(jìn)程的阻塞事

件可能會(huì)很快發(fā)生,則可將一個(gè)Blocked,Suspend進(jìn)程換入內(nèi)存,變?yōu)锽locked

?RunningReady,Suspend:當(dāng)執(zhí)行進(jìn)程的時(shí)間片用完時(shí),會(huì)轉(zhuǎn)換為Ready。

或,一個(gè)高優(yōu)先級(jí)的Blocked,Suspend進(jìn)程正好變?yōu)榉亲枞麪顟B(tài),OS可以將執(zhí)

行進(jìn)程轉(zhuǎn)換為Ready,Suspend狀態(tài)

?AIIExit;通常,RunningExito但某些OS中,父進(jìn)程可以終止其子進(jìn)程,

使任何狀態(tài)的進(jìn)程都可轉(zhuǎn)換為退出狀態(tài)

ProcessDescription

?問(wèn)題:

OS如何感知進(jìn)程、控制進(jìn)程及其所用的系統(tǒng)資源?

p〃

Virtiuil

Mem?y

ComfMitrr

Resources

3.9Prwessesa?dResources(reMMirceadkxrationat<HM?snapshotintime)

OperatingSystemControlStructures

?Informationaboutthecurrentstatusofeachprocessand

resource

?Tablesareconstructedforeachentitytheoperating

systemmanages

一MemoryTables

-I/OTables

FiIeTables

ProcesTable

Fimirc3.10Genera]Structure*OiM*ratiiwSystemControlTnNc

MemoryTables

?AIlocationofmainmemo-ytoprocesses.

?AIlocationofsecondarymemorytoprocesses.

?Protectionattributesforaccesstosharedmemoryregions.

?InformalionneededtomanagevirtuaImemory(虛擬存儲(chǔ))

I/OTables

?I/OdeviceisavailabIeorassigned.

?Statusof1/0operation.

?Locationinmainmemorybeingusedasthesourceor

destinationofthe1/0transfer.

FiIeTables

?Existenceoffiles.

?Locationonsecondarymemory.

?CurrentStatus.

?Attributes.

?Some!imesthisinformationismaintainedbyafiIe-managementsystem.

ProcessTabIe

?Whereprocessislocated.

?Attributesnecessaryforitsmanagement.

?ProcessID

?Processstate

?Locationinmemory

ProcessLocation

?ProcessincIudessetofprogramstobeexecuted.

?DatalocationsforIocaIandglobaIvariables.

?Anydefinedconstants.

?Stack.

?ProcesscontroIbIock(PCB)

?CoIlectionofattributes.

?Processimage(進(jìn)程映像)

?CoIlectionofprogram,data,stack,andattributes.

Processimage

?UserData

?UserProgram

?SystemStack:存放系統(tǒng)及過(guò)程調(diào)用地址、參數(shù)

?ProcessControIBlock(PCB):OS感知進(jìn)程、控制進(jìn)程的數(shù)據(jù)結(jié)構(gòu)

ProcessControIBlock

?簡(jiǎn)稱PCB:是OS控制和管理進(jìn)程時(shí)所用的基本數(shù)據(jù)結(jié)構(gòu)

?作用:PCB是相關(guān)進(jìn)程存在于系統(tǒng)中的唯一標(biāo)志;系統(tǒng)根據(jù)PCB而感知相關(guān)

進(jìn)程的存在。

?內(nèi)容:通常情況下,PCB包含Identifiers(標(biāo)識(shí))、狀態(tài)、控制、指針等

多種信息。

ProcessControIBlock(PCB)

?Processidentification

?Identifiers

?Identifierofthisprocess(進(jìn)程ID)

?Identifieroftheprocessthatcreated

thisprocess(parentprocess)(父進(jìn)程ID)

?Useridentifier(用戶ID)

ProcessControIBlock

?ProcessorStateInformation

■User-VisibIeRegisters(用戶可見寄存器)

?Auser-visibleregisterisonethatmaybereferencedbymeans

ofthemachineIanguagethattheprocessorexecutes.

?Typically,therearefrom8to32oftheseregisters,although

someRISCimplementationshaveover100.

ProcessControIBlock

?ProcessorStateInformation

?ControIandStatusRegisters

Thereareavarietyofprocessorregistersthatareemployedto

controItheoperationoftheprocessor.Theseinclude

?Programcounter:Containstheaddressofthe

nextinstructiontobefetched.

?Conditioncodes:ResuItofthemostrecent

arithmeticorlogicaIoperation(e.g.rsign,

zero,carry,equaI,overflow).

?Statusinformation:Includesinterrupt

enabled/disabledflags,executionmode.

ProcessControIBlock

?ProcessorStateInformation

?StackPointers

?Eachprocesshasoneormorelast-in-first-out(LIFO)

systemstacksassociatedwithit.

?AstackisusedtostoreparametersandcaIIing

addressesforprocedureandsystemcaIIs.

?Thestackpointerpointstothetopofthestack.

ProcessControIBlock

?ProcessControlInforma11on

?ScheduIingandStateInformation

?Processstate:definesthereadinessofthe

processtobescheduledforexecution(e.g.,

running,ready,waiting,haIted).

?Priority:OneormorefieIdsmaybeusedto

describethescheduIingpriorityofthe

process.

?Scheduling-relatedinformation:ThiswiII

dependonthescheduIingaIgorithmused.

?Event:Identityofeventtheprocessis

awaitingbeforeitcanberesumed

ProcessControIBlock

?ProcessControIInformation

?DataStructuring

?AprocessmaybeIinkedtootherprocess

inaqueue,ring,orsomeotherstructure.

?Aprocessmayexhibitaparent-chiId

(creator-created)reIationshipwith

anotherprocess.

?TheprocesscontroIblockmaycontain

pointerstootherprocessestosupport

thesestructures.

ProcessControIBlock

?ProcessControIInformation

?IntorprocessCommunication

?Variousflags,signaIs,andmessagesmaybeassociated

withcommunicationbetweentwoindependentprocesses.

?ProcessPrivileges

?Processesaregrantedprivilegesintermsofthememory

thatmaybeaccessedandthetypesofinstructionsthat

maybeexecuted.

ProcessControIBlock

?ProcessControIInformation

?MemoryManagement

?Thissectionmayincludepointerstosegment

and/orpagetablesthatdescribethevirtuaI

memoryassignedtothisprocess.

?ResourceOwnershipandUtiIization

?ResourcescontroIledbytheprocessmaybe

indicatedysuchasopenedfiles.Ahistory

ofutiIizationoftheprocessororother

resourcesmayaIsobeincluded;this

informationmaybeneededbythescheduIer.

ProcessControIBlock

Pnxr^

kknlinoiliimkknllfk?atk?iklrntlfkjitlim

1PFWTM%

FrucnaurStaleFroreMTStaleFruce?oStaleL<

InformationInformationInfurmatiuafBlock

Prncf('untruiFrwe*CunlruiC<jolrt4

InhirmilliMiInTormnllimInhirmatkm

[RrStockl?erSUK<txrsuct

FrhateIwrFrhateIwFfivateIf

AcklreviSpacrAcklFMSpacrAckirmSpore

<Fru(*ramNDaUi?(Prufu-an*^Dalai<Pruuram.DaUi

ShftrcdActinoSharedAdrtmftSharedAddrvw

SpaceSpaceSpace

Pnwv^1FnrKVM2PFIKV^A.

Figure3.12txerPrixTe-Memory

TypicalFunctionofanOSKernel(資源管理功能)

?ProcessManagement:進(jìn)程創(chuàng)建和終止、調(diào)度、狀態(tài)轉(zhuǎn)換、同步和通

信、管理PCB

?MemoryManagement:為進(jìn)程分配地址空間、對(duì)換、段/頁(yè)管理

?I/OManagement:緩存管理、為進(jìn)程分配I/O通道和設(shè)備

TypicalFunctionofanOSKernel(支撐功能)

?InterrupthandIing(中斷處理)

?Timing(時(shí)鐘管理)

?Primitive(原語(yǔ)):AtomicOperation

?Accounting(統(tǒng)計(jì))

?Monitoring(監(jiān)測(cè))

ProcessControIPrimitives(原語(yǔ))

?ProcessSwitch,進(jìn)程切換

?CreateandTerminate,創(chuàng)建與終止

?BlockandWakeup,阻塞與喚醒

?SuspendandActivate,掛起與激活

WhentoSwitchaProcess

?Clockiinterrupt

?processhasexecutedforthemaximumaIlowabIetimesIice

(時(shí)間片)

?I/Ointerrupt

?MemoryfauIt(存儲(chǔ)訪問(wèn)失效)

?memoryaddressisinvirtuaImemorysoitmustbebrought

intomainmemory

WhentoSwitchaProcess

?Trap(陷阱)

?erroroccurred

?maycauseprocesstobemovedtoExitstate

?SupervisorcaII(管理程序調(diào)入)

?suchasfiIeopen

ChangeofProcessState

?SavecontextofprocessorincIudingprogramcounterandotner

registers

?UpdatethePCBoftheprocessthatiscurrentlyrunning

?MovePCBtoappropriatequeue-ready,bIocked

?Selectanotherprocessforexecution

ChangeofProcessState

?UpdatethePCBoftheprocessselected

?Updatememory-managementdatastructures

?Restorecontextoftheselectedprocess

ProcessSwitchingvs.Mode

Switching

?ProcessSwitch,是作用于進(jìn)程之間的一種操作。

當(dāng)分派程序收回當(dāng)前進(jìn)程的CPU并準(zhǔn)備把它分派

給某個(gè)就緒進(jìn)程時(shí),該操作將被引用。

?ModeSwitch,是進(jìn)程內(nèi)部所引用的一種操作。當(dāng)

進(jìn)程映像所包含的程序引用核心子系統(tǒng)所提供的

系統(tǒng)調(diào)用時(shí),該操作將被引用。

ProcessGreation

?Submissionofabatchjob

?UserIogson

?Createdtoprovideaservicesuchasprint

?Processcreatesanotherprocess

ProcessGreation(creat。原語(yǔ),步

驟)

1.為進(jìn)程分配一個(gè)唯一標(biāo)識(shí)號(hào)ID:主進(jìn)程表中增加一個(gè)新的表項(xiàng)

2?為進(jìn)程分配空間:用戶地址空間、用戶棧空間、PCB空間。若

共享已有空間,則應(yīng)建立相應(yīng)的鏈接。

3.初始化PCB:進(jìn)程標(biāo)識(shí)、處理機(jī)狀態(tài)信息、進(jìn)程狀態(tài)

4.建立鏈接:若調(diào)度隊(duì)列是鏈表,則將新進(jìn)程插入到就緒或(就

緒,掛起)鏈表

5.建立或擴(kuò)展其他數(shù)據(jù)結(jié)構(gòu)

ProcessTermination(終止)

?BatchjobissuesHalt\nstruction

?Userlogsoff

?Quit(退出)anappIication

?ErrorandfauItconditions

ReasonsforProcessTermination

?NormaIcompletion,正常結(jié)束

?TimeIimitexceeded,超時(shí)終止,執(zhí)行時(shí)間超過(guò)預(yù)計(jì)時(shí)間

?MemoryunavaiIable,內(nèi)存不足,無(wú)法為進(jìn)程分配所需的內(nèi)存空間

?Boundsviolation,越界訪問(wèn)

?Protectionerror,企圖使用未允許用的數(shù)據(jù),或操作方式錯(cuò)

?Arithmeticerror,計(jì)算錯(cuò),如除零,或企圖存儲(chǔ)硬件允許的最大數(shù)

?Timeoverrun,超時(shí)等待某事件發(fā)生

ReasonsforProcessTermination

?I/Ofailure,如找不到文件或多次重試仍無(wú)法讀寫文件,或無(wú)效操作

?InvaIidinstruction,企圖執(zhí)行不存在的指令

?PriviIegedinstruction,企圖執(zhí)行特權(quán)指令

?Datamisuse,數(shù)據(jù)類型不符,或未初始化

?Operatingsystemintervention,操作員或OS干預(yù),如發(fā)生死鎖的時(shí)候

?Parentterminates,sochiIdprocessesterminate

?Parentrequest

ProcessTermination(destroy。原語(yǔ),

步驟)

1.根據(jù)被終止進(jìn)程的標(biāo)識(shí)符ID,找到其PCB,讀出該進(jìn)程的狀態(tài);

2.若該進(jìn)程為執(zhí)行狀態(tài),則終止其執(zhí)行,調(diào)度新進(jìn)程執(zhí)行;

3.若該進(jìn)程有子孫進(jìn)程,則立即終止其所有子孫進(jìn)程

4.將該進(jìn)程的全部資源,或歸還給其父進(jìn)程,或歸還給系統(tǒng)

5.將被終止進(jìn)程(的PCB)從所在的隊(duì)列中移出,等待其它程序來(lái)

搜集信息

ProcessBlockandWakeup(阻塞的原

因)

?請(qǐng)求系統(tǒng)服務(wù)

?啟動(dòng)某種操作:如I/O

?新數(shù)據(jù)尚未到達(dá)

?無(wú)新工作可做

ProcessBIockandWakeup(原語(yǔ))

?阻塞原語(yǔ)block。

當(dāng)出現(xiàn)阻塞事件,進(jìn)程調(diào)用阻塞原語(yǔ)將自己阻塞。狀態(tài)

變?yōu)椤白枞麪顟B(tài)”,并進(jìn)入相應(yīng)事件的阻塞隊(duì)列

?喚醒原語(yǔ)wakeup()

當(dāng)阻塞進(jìn)程期待的事件發(fā)生,有關(guān)進(jìn)程調(diào)用喚醒原語(yǔ),

將等待該事件的進(jìn)程喚醒。狀態(tài)變?yōu)镽eady,插入就緒隊(duì)列

ProcessBIockandWakeup(原語(yǔ))

?掛起原語(yǔ)suspend()

當(dāng)出現(xiàn)掛起事件,系統(tǒng)利用掛起原語(yǔ)將指定進(jìn)程或阻

塞狀態(tài)進(jìn)程掛起。進(jìn)程從內(nèi)存換到外存,狀態(tài)改變:

ReadyReady,Suspend;BIocked

Blocked,Suspend,插入相應(yīng)隊(duì)列

?激活原語(yǔ)active()

當(dāng)激活事件發(fā)生,系統(tǒng)利用激活原語(yǔ)將指定進(jìn)程激活。

進(jìn)程從外存換入到內(nèi)存,狀態(tài)改變:Ready.Suspend

Ready;Blocked,SuspendBlocked,插入相應(yīng)隊(duì)列

Thread(線程)

?Anexecutionstate(running,ready,etc.)

?Savedthreadcontextwhennotrunning.

?Hasanexecutionstack.

?Someper-threadstaticstorageforIocaIvariables.

?Accesstothememoryandresourcesofitsprocess.

?aIIthreadsofaprocesssharethis.

Siiigle-llirviMiccIMultitlireaded

Prix^ssModelPr<>cv**sModel

Iser

Acklre**

Space

Eiuiire4.2SingleThreudvdandMultithreadedProcessMcxkls

BenefitsofThreads

?Takeslesstimetocreateanewthreadthana

process.

?Lesstimetoterminateathreadthanaprocess.

?Lesstimetoswitchbetweentwothreadswithin

thesameprocess.

?Sineethreadswithinthesameprocessshare

memoryandfiIes,theycancommunicatewith

eachotherwithoutinvokingthekerneI.

Threads

?SuspendingaprocessinvoIvessuspendingaIIthreadsof

theprocess

?sinceaIIthreadssharethesameaddressspace.

?Terminationofaprocess,terminatesaIIthreadswithin

theprocess.

MuItithreading

?OperatingsystemsupportsmuItipIethreadsof

executionwithinasingIeprocess.

?MS-DOSsupportsasingIethread.

?UNIXsupportsmuItipIeuserprocessesbutonIy

supportsonethreadperprocess.

?Windows2000,SoIaris,Linux,Mach,andOS/2

supportmuItipIethreads.

rmiltlpirpnmw*multiplepnCTM**

oneIhrvxlperpncwmultiplethrvachperpr1n

ImtriKtliiciIrace

Eiuure4.1TlirvmlsaixiPr?MessrsIANDE97

ThreadStates

?KeystatesforathreadRunning,Ready,Blocked.

?Operstionsassociatedwithachangeinthreadstate.

?Spawn(派生),Spawnanotherthread

?Block

?Unblock

?Finish

User-LeveThreads

?AIIthreadmanagementisdonebytheappIication.

?ThekerneIisnotawareoftheexistenceofthreads.

?描述此類線程的數(shù)據(jù)結(jié)構(gòu)以及控制此類線程的原語(yǔ)在核外子系統(tǒng)中實(shí)現(xiàn)。

KerneI-LeveIThreads

?W2KrLinux,andOS/2areexamplesotthisapproach.

?Ker

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論