• Aucun résultat trouvé

EcOde: Error 1na1cator

Dans le document Operating System Reference Manual (Page 64-86)

Vnare: Voll.De nane

Password: Passwrd for device (currently ignored) Devnane: Device name

T/1e FIle System

twn.NT and LtfvILNT handle access to sequential devices or block-structured deVices. For blOCk-structured devices, twn.NT logically attaches the volume's catalog to the File System. The name of the volt.me mot.rlted is returned in the ~ parameter.

LtfvILNT detaches the speCified volume from the FHe System. No object on tnat volume can be opened after LtfvILNT has been Called. The volume cannot be unrrtru"Ited untll all the objects on the volume have been closed by

wI

processes using them.

DEM&ne Is the name of the device on whiCh a volume Is being mountect.

DEM&ne ShoUld be given withOUt a leading dash (-~

vncme Is the ncme Of the volume that was succesSfully mounte(j, and Is returned.

Chapter 3 Processes

3.1 Process St.ructlJre •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 3-2 3.2 Process l-tlerarct1y ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 3-2 3.3 PItlcess creaUm •...•...•.•••.•••••••••.•.•..••....••....•••.•••••.•.•....••••.•••.•..•.. 3-3 3.4 PItlcess c:or.tIol •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 3-3 3.5 Process setm.dIrlg •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 3-3 3.6 ~ TenTdI'latlOl1 •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• 3-4 3.7 A PItlcess-tiClldlIrlg ExarT1Jle ••.••••••••••••••••••••••••••••••••••••.•.•••••••••••••••••••• 3-5 3.8 PItlcess SysterTl C8Ils ••••••••••••••••••••••••••••••••••••••••••••••••••••.•••••••••••••••••••• 3-7 3.8.1 M.AJ<E PROOESS •...•....•..•....•...•.••...•.•..•..•••..•.•.•...•••.•.••••.••. 3-8 3.8.2 TERMiNATE PROCESS ...•...•...•....•...•...•....•.••. 3-9 3.8.3 II'F"O PROOESs .•..••...•.•.••..••..••...•.••.•.••••.••..•.•••..•..•..••...•...••••.. 3-11 3.8.4 KILL:'PROCESS ... 3-13 3.8.5 SlJSPEI\I) PROCESS ... 3-14 3.8.6 ACTIVATE PROCESS •...•..•.••.•.•.••...•.•.•••..•.•...••..•.•...•...•..•.• 3-15 3.8.7 SETPRI~ITY PROCESS ••..•.•.•.•.•.•.•.••••.••.••.••.••••...•••...•...•..•••.. 3-16 3.8.8 YIELD CPU .:: ..•..•...•..•..•....••....••...•.•.••.•...•...•.•... 3-17 3.8.9 MY _10-: ••.•.•••.•••.•••••.••••.•••.•••••••••.•.•.•.•.••••••••.•••••••.••.•..•••••••••••• 3-18

Processes

A process is an entity in the Lisa system that performs work. When you ask the qJerating System to run a program .. the OS creates a specific instance of the program and its associated data. That instance is a process.

The Lisa can have a number of processes at anyone time; they appear to be running sImultaneously. Although processes can Share code and data eaCh process has its own stack.

011 y one process at a time can use the CPU. The SclJeduler determines which process is active at a particular time. The Scheduler allows each process to run until some condition that would slow execution occurs (an I/O request .. for example~ At that time .. the running process is saved in its current state. The Scheduler then checks the pool of ready-to-run processes.

When the original process later resumes execution .. it piCkS up where it left off.

The process SChedullng state has three possibill ties. A 1lll1lJlng pR7cess Is actually executing instructions. A .ready process is ready to execute but is beIng held back by the Scheduler. A blOCked PIVtJeSS Is Ignored by the Scheduler. It cannot continue its execution until something causes it to

become ready. Processes commonly become blocked whlle awaIting completion of I/O .. although there are a number of other llkel y causes.

Processes

3.1 Process Structure

A process can use up to 16 data segments and 106 cOde segments.

Process Address Space Layout

Each process has an associated priority, an integer between 1 and 255. The

SCheOuler usually executes the highest-priority ready process. The higher priorities (226 to 255) are reserved for the q,erating System.

The fvIemory I'18n8ger process handles cOde and data segment swapping.

q:JeratJng system Reference MantIaJ Processes The Shell process Is a user process tnat Is automatically started when the OS Is InitIallzed. It Is typically a command interpreter, bUt It can be any program. The OS simply lOOkS for the program called SYSTEM.SHELL and

executes It

Root Process

/

Process Shell

I~

Memory MlllBger

I

Ottler

Process U ser Process

Other User Processes

11\

Fl~ 3-2

Process Tree

My other system process (the network control process, for example) Is a son of the root process.

3..3 Process creatloo

When a process is created, it is placed in the ready state with a priority equal to that of the process that created it. All the processes created by a given process can be thOUght of as existing in a subtree. Many of the process management calls affect the entire subtree of a process as well as the process itself.

3.4 Process COOtrol

Three system calls are provIded for explicIt control of a process. These calls allow a process to kill, suspend (blOCk)., or activate any other user process In

the system, as long as the process Identifier Is known. Process-handl1ng calls are not allowed to control ~rat1ng System processes.

3..5 Process SChetUlrYJ

Process SChedUling is based on the priority established for the process and on requests for C\)erating System services.

The SchedUler generally executes the highest-prtority ready process. O1Ce a process is executing, it loses the CPU only under certain cIrcumstances. The

CPU Is lost When there Is some specIfIc request for the process to wait (for an event, for example), when there Is an I/O request, or when there Is a reference to a code segment that Is not In memory. A process that makes

t.pelCJllng Syslel? Refel-ent-:tJ I'1anttal Processes

• The runnIng process activates a hIgher-prIority process.

• The running process suspends itself.

• A higher-priority process becomes ready.

• The running process needs code to be swapped into memory.

• The runnIng process executes an event -wal t call.

• The running process calls DELAY _ TlIVE.

Because the ~eratlng System cannot seIze the CPU from an executing process except In the cases noted above, baCkground processes should be liberally sprinkled with YIELD_CPU calls.

When the Scheduler is invoked, it saves the state Of the current process and

3.6 Process TerminatiCX'l

A process terminates under one of the followIng condItions:

• It calls TERMINATE_PROCESS.

• It reaches an 'EN): statement process terminates Immediately.

qJeratfng Systen7 RefelmtJe fvlantl8.l

Processes

A process can call KlLL_PRCCESS on any user process whose Proc_Id Is known. TERMINATE_PRl£ESS, on the other hand, terminates the process that caHea It (ana lts aescendants~ TERMINATEYROCESS also allows an event to be sent to the father of the terminating process if a local event channel was speclflea In the MAKE_PROCESS cal1.

Termination involves the followIng steps:

1. SIgnal the SYS _TERMINATE exception on the terminating process.

2. Execute the user's exception handler, if any.

3. Instruct all sons of the current process to termlnate.

4. Close all open fUes, data segments.pipes, and event channels left open by the user process.

5. Send the SYS_SCN_ TERM event to the father of the termInatIng process I f a local event channel exists.

6. Wal t for all the sons to finIsh termination.

3.7 A Process-Hand11ng Example

The following programs illustrate the use of many of the process-management calls described In thIs Chapter. The program Father .. below .. creates a son process and lets it run for a while. It then gives the user a chance to activate, suspend, kilL or get information about the son.

PRffiRAf1 Fatner;

USES ("1U SCJurce:Sy5Call.(])j*) Sy5Call;

VAR Errorcode:INTEGER; (*error returns from system calls *) proc_id:LONGINT; (* process global identifier *)

pr()(J18lOO:PattTlcloo; (* program file to execute *) rull:NcIIestring; (* progran entry point *)

InfO_Rec:ProclnfoRec; (* information aboUt process *) i : INTEGER;

Answer: CHAR;

Q:Jemting System Reference MantJal Processes

BEGIN

ProrIBE:='sm..OOJ';

(* this prognn is defined belOW-) ttJll:=" ;

MAKE_PRaSS(Errol'Code, Proc_Id,

ProrIBE,

tt.lll, 0);

If (Errol'COde<>O) ll£N

WUTELN('Error ',Errol'Code,' 0Jr~ process magemellt. ');

Fm i:=l TO 15 00 (* idle for aWlile *) BEGIN

IRITB..N(, father executes for a nonent. ' );

VIElOJPU(Errol'Code,FN...SE); (* let son 1Ul *) EN>;

WUTE('K(ill S(uspend A(otivate l(nfo');

REAOlN(Answer );

IRITELN(,SOO' 's rraIe is ',Info_Reo.~ttt8E);

00;

00;

If (ErroI'Code<>O) ll£N

IRITElN( • Error " Errol'Code,' during process no agenBlt. ' );

VIElO_(]ltJ(Errol'Code, fN...SE); (*let father process 1'lIl*) END;

EN>.

qJeratJng system Reference ManIJal Processes 3.8 Process system calls

This section describes the (\)eratlng system calls that pertain to process control. A summary Of all the Qleratlng system calls can be fotnl In

~ndlx A The following special types are used in process-control calls:

Pattnlle

=

SlRIt«2[255];

NamestrilYJ = SlRItf3[20];

P s eventblock

=

"'s eventblock;

S-eVentblock

=

T

event

text;

{~event_text

= array

[0 .. size_etext] of 1~1nt;

ProclnfoRec = record

pmpattTlaIE : patI'IlcIE;

glObal_id : longint;

father_id : Imgint;

priority : 1 •• 255;

state : (pactive, psuspellded, pwaiting);

data in : boolecl'l

end;-cpe.ratlng System Reference HantlaJ

3.8.1 MAKE_PRoc:ESS Process System can MAKE_PR«n:SS (var ErrtUn:lnteger;

Var Proc_Id:lcnJlnt;

Var Prot;f"11e: Patt"flc:llE;

Processes

Var EntryNalE:NcIIEString; (it NanEString

=

STRlt«2[20] it) Evnt_Ohn_RefNum:lnteger)

ErrNum:

Proc Id:

progFlle:

EntryName:

Evnt_Chn_RefNum:

Error indicator

Process identifier (globally unique) Process file nalOO

Program entry point

Communication channel between calling process and created process

A son process is created when another process ... the father process ... calls MAKE_PROCEss. The son process executes the program identified by the pathname in ~Ue. If ~l1e is a null character string... the program name of the father process is used. A globally unique identifier for the son process is returned in Proc_Id.

Evnt_CtIl_RefNt.m is a local event channel supplied by tne father process.

Event channels are discussed In Chapter 5. The ~erating System uses tne event channel identlfled by Evnt_CtIl_RefNtm to send the fatner process events regarding the son process (for example ... SYS_SCN_ TERM~ If

Evnt_ CtIl_Refl\Un Is zero ... tne fatner process Is not Informed 'When such events are prOduCed.

EntryNcme, if non-null ... specifies the program entry point where execution is to begin. Because alternate entry points have not yet been defined for Pascal, this parameter is currently ignored.

My error encountered durIng process creat10n Is reported In Errf\lm

Q'JeJC1t1ng SyStenl Reference I'-1anI.Ia1

3.82 TERMINATEJ'ROCESS Process System call TERMINATE JlRlnSS(Var ErrttJn : Integer;

Event_ptr:P_s_eventblk}

ErrNum: Error indicator

Event_Ptr: Information sent to process's creator

Prol.:·esses

Excep _DaU:{O] - 0 Process called TERMINATE_PROCESS.

1 Process executed the 'EN:J.· statement.

2 Process called KILL_PROCESS on ltself.

3 Some other process called KILL_PROCESS on the terminating process.

4 Father process Is terminatlng.

5 Process made an invalid system call (that is" an

fJJeJ'atlng system Reference I'1antI8l

Prroesses

SYS_TERMINATE exception information blocK. My user-supplled data in the

first longlnt of the event text is overwritten.

If a process specifies an event to be sent In the TERMINAlE_PROC':ESS call but the process was created without a local event channel, no event Is sent to

the father.

If the process was created wIth a local event Channel, an event Is sent to the father if the process calls TERMINATE_PRDJESS with a nll Event_PU or if the process termInates by a means other than Calling TERMlNATE_PR~SS.

The event contains the termination cause In the first longlnt and zeroes In the remaInIng event text.

P _S_everltblk Is a pointer to s_everltblk, defined as:

C(H)T size_ etext = 9;. (* event text size - 40 bytes *) TYPE t_evet'lt_text

=

MRAV [0 •• slze_etext) (F LongInt;

s_eventblk = t_evet1t_text;

If a process calls TERMINATE_PRCCESS twice, the ~rat1ng System forces it

to terminate even if it has disabled the terminate exception.

qJerating System Reference Manual

3.8.3 II'FO _PROOESS Process system call UFO_PROCESS (Var ErrNlIn:Integer;

Proc_Id:Longlnt;

Var Proc_Info:ProcInf~);

ErrNum: Error indicator

Proc Id: Global identifier of process

Processes

Proc=Info: Information about the process identified by Proc_Id

A process can call II\FO_PRo:::ESS to get a variety of information about any process known to the cperating System. Use the function MY _10 to get the Proc_Id of the calling process.

ProclnfoRec is defined as:

TYPE Proclnf~ = REcmD

~'tt1'lanE :Pa'tt1'lanE;

Global_id : Longint;

Priority : 1 .. 255;

state : (PActi ve, PSuspewlded, Pwai ting);

oata

_in : Boolea'l EM);

Data_In InOlcates Whether the data space of the process Is currently In memory.

The procedure on the next page gets information about a process and displays some of it.

t:pemllng System Reference Manual

PROCEDURE Oisplay_Info(Proc_Id:lONGINT);

VAA ErrorCOde: INTEGER;

Info Rec:ProcInfoRec;

BEGIN

-INFO_PROCESS (ErrorDode, Proc_Id, InfO_Rec);

IF (ErrorGode=100) THEN

IRITElN("Attempt to display info about nonexistent

process. ") ELSE

BEGIN

.Im

Info Rae 00 BEGIN

-IRI TELN( I program nanE: ", P1'OC1'at:hNclle);

IRITELN(" global id: ", Global_id);

IRITELN(" priority: ", priority);

IRITE(" state: ");

CASE State (F

PActi ve : IRITELN( I active I ) ; PSuspended: IRIffiN( I suspended I ) ; Plaiting: IRITELN("waiting")

EM)

Ot)

EM) EN);

Processes

qJeratlng System Reference Hanual 3.8.4 K1LL_PRo:::ESS Process System Call

KILL_PROCESS (var ErrtUl:lnteger;

Proc_Id:Longlnt) ErrNum:

Proc_Id: Error indicator Process to be killed

Processes

KILL_PROCESS kills the process referred to by Proc_Id and all of the

processes in its sUbtree. The actual termination of the process does not occur until the process is In one of the followIng states:

• Executing in user mode.

• Stopped due to a SUSPEI'V_PRCCESS call.

• Stopped due to a CELAY _TIM: call.

• Stopped due to a WAIT_EVENT _ a-N or SEI'V _EVENT _a-N call, or READ_DATA or WRITE_DATA to a pipe.

cperatfng System Reference Manual

3.8.5 SLISPENJ _PRoc:ESS Process System Call

SlJSPEN) J'ROCESS (Var Errtt.ln: Integer;

Proc_Id:LongInt;

SUsp_Fanl1y:Booleal) ErrNum: Error indicators Proc_Id: Process to be suspended

Processes

susp-Family: If true~ suspend the entire process subtree SLISPENJ_PRoc:ESS allows a process to suspend (block) any process In the system. The actual suspension does not occur until the process referred to by Proc_Id Is In one of the following states:

• Executing In user mode

• Stopped due to a DELAY _ ntvE call

• Stopped due to a WAIT_EVENT _ c::H\I call

NeIther expiration of the delay time nor receipt of the awaited event causes a suSpended process to resume execution. SUSPEf\IJ_PRC£ESS Is the only direct way to blOCK a process. Processes~ however~ can become blocKed durIng

I/O, by the timer (see DELAY _ TIf"'E)~ or for many other reasons.

If SUSp_Fcmlly Is true, the ~rat1ng system suspends both the process referred to by Proo_ld and all of its descendents. If SUSpycmlly Is false~

only the process identified by Proc_Id is suspended.

t:peratlng System Reference Hanual

3.8.6 ACTlVAlE_PROOESS Process system Call ACTIVAlE _FJRCn:SS(var ErrtQn: Integer;

Proc _ Id: LongInt;

Act_Family:Boolean) ErrNum: Error indicator

Proc Id: Process to be activated

Processes

Act_Family: If true, activate the entire process subtree To awaken a suspended process, call ACTIVAlE_PRoc:Ess. A process can activate any other process in the system. Note that ACTIVATE_PROOESS can awaken only a suspended process. If the process is blocKed for some other reason, ACTIVATE_PRoc:ESS cannot unblock it. If Act_Fcl1l11y is true,

ACTlVATE_PRoc:ESS also activates all the descendents of the process referred to by Proc_Id.

cperatlng System Reference Manual

3.8. 7 SETPRIfRITY _ PRoc:ESS Process System Call

SETPRUIUTY J:lROCESS(Var ErrtU1: Integer;

Proc_Id:loogInt;

NeW_Priority:Integer) ErrNum: Error indicator

Proc Id: Global id of process

New_Priority: Process's new priority number

Processes

SETPRIfRITY _ PRoc:ESS changes the scheduling priority of the process

referred to by Proo_ld to New_Priority. The priority value must be between 1 and 225. (qlerating System processes execute with priorities between 226 and 255.) The higher the priority ... the more likely the process is to be allowed to execute.

cperating System Reference Manual

3.8.8 YIELD_CPU Process System Call

VIElD_CPU(Var ErrNum:lnteger;

TO_Any:Boolecl1) ErrNum: Error indication

To_Any: Yield to any process, or only higher or equal priority

Processes

Background processes should use YIELD _ a='U often to allow other processes to execute when they need to. Success! ve yields by processes of the same priority result in a "round robin" scheduling of the processes. If TO_Any is true, YIELD_CPU causes the calling process to yield the CPU to any other ready process. If To_Any is false, YlELD_a='U causes the calling process to give the CPU to any other ready-to-execute process with an equal or higher priority. If no process meets the TO_Any criterion, the calling process simply continues execution.

t:perating System Reference Mantlal

3.8.9 MY _10 Process System Call t1Y_ID:Longint

Processes

MY _10 Is a function that returns the unique glooal identifier (a longint) of the

call1ng process. A process can use MY _10 to perform process handllng calls

on itself.

for example:

setPriority_Process(ErrtUQ, My_Id, 100) sets the priority of the call1ng process to 100.

Chapter 4

Dans le document Operating System Reference Manual (Page 64-86)

Documents relatifs