Sie sind auf Seite 1von 53

Process Description and Control

Chapter 3

Concepts
Computer platform consists of a collection of hardware resources Computer applications are developed to perform some task Inefficient for applications to be written directly for a given hardware platform Operating system provides a convenient to use, feature rich, secure, and consistent interface for applications to use O provides a uniform, abstract representation of resources that can be re!uested and accessed by an application

"anage #$ecution of %pplications


&esources made available to multiple applications Processor is switched among multiple applications 'he processor and I(O devices can be used efficiently

Process
% program in e$ecution %n instance of a program running on a computer 'he entity that can be assigned to and e$ecuted on a processor % unit of activity characteri)ed by the e$ecution of a se!uence of instructions, a current state, and an associated set of system resources

"a*or &e!uirements of an Operating ystem


Interleave the e$ecution of several processes to ma$imi)e processor utili)ation while providing reasonable response time %llocate resources to processes upport interprocess communication and user creation of processes

Process #lements
Identifier tate Priority Program counter "emory pointers Conte$t data I(O status information %ccounting information

Process Control +lock


Contains the process elements Created and managed by the operating system %llows support for multiple processes

Process Control +lock

'race of a Process
e!uence of instructions that are e$ecuted by a process 'he trace can be used for optimi)ation and(or debugging purposes, Dispatcher switches the processor from one process to another

#$ample #$ecution

'race of Processes

'wo- tate Process "odel


Process may be in one of two states
. &unning . /ot-running

/ot-&unning Process in a 0ueue

Process Creation
ubmission of a batch *ob 1ser logs on Created to provide a service such as printing Process creates another process

Process 'ermination
+atch *ob issues Halt instruction 1ser logs off 0uit an application #rror and fault conditions

&easons for Process 'ermination


/ormal completion 'ime limit e$ceeded "emory unavailable +ounds violation Protection error
. e$ample write to read-only file

%rithmetic error 'ime overrun


. process waited longer than a specified ma$imum for an event

&easons for Process 'ermination


I(O failure Invalid instruction
. happens when we try to e$ecute data

Privileged instruction Data misuse Operating system intervention


. such as when a deadlock occurs

Parent terminates so child processes terminate Parent re!uest

Processes
/ot-running
. ready to e$ecute

+locked
. waiting for I(O

Dispatcher cannot *ust select the process that has been in the !ueue the longest because it may be blocked

% 2ive- tate "odel


&unning &eady +locked /ew #$it

2ive- tate Process "odel

'ransitions
Running -> Blocked 3I(O operation, waiting for an event, waiting for a communication to complete Running -> Ready 3 preemption, timeout Blocked -> Exit : Ready -> Exit : % process can almost always transfer to the Exit state given the right circumstances 4forced to e$it5,

Process tates

1sing 'wo 0ueues

"ultiple +locked 0ueues

uspended Processes
Processor is faster than I(O so all processes could be waiting for I(O wap these processes to disk to free up more memory +locked state becomes suspend state when swapped to disk 'wo new states
. +locked, suspend . &eady, suspend

One uspend tate

'wo uspend tates

&easons for Process uspension

"odes of #$ecution
1ser mode
. 6ess-privileged mode . 1ser programs typically e$ecute in this mode

ystem mode, control mode, or kernel mode


. "ore-privileged mode . 7ernel of the operating system

CP6 4Current Privilege 6evel5 bits in most CP1s

Process Creation
%ssign a uni!ue process identifier %llocate space for the process Initiali)e process control block et up appropriate linkages
. #$3 add new process to linked list used for scheduling !ueue

Create of e$pand other data structures


. #$3 maintain an accounting file

Process witching "echanisms


Clock interrupt
. process has e$ecuted for the ma$imum allowable time slice

I(O interrupt "emory fault


. memory address is in virtual memory so it must be brought into main memory

Process witching "echanisms


'rap
. error or e$ception occurred . may cause process to be moved to #$it state

upervisor call
. such as file open

Change of Process tate


ave conte$t of processor including program counter and other registers 1pdate the process control block of the process that is currently in the &unning state "ove process control block to appropriate !ueue . ready8 blocked8 ready(suspend elect another process for e$ecution

Change of Process tate


1pdate the process control block of the process selected 1pdate memory-management data structures &estore conte$t of the selected process

O #$ecution
/on-process 7ernel
. #$ecute kernel outside of any process . Operating system code is e$ecuted as a separate entity that operates in privileged mode

#$ecution 9ithin 1ser Processes


. Operating system software within conte$t of a user process . Process e$ecutes in privileged mode when e$ecuting operating system code

#$ecution of the Operating ystem


Process-+ased Operating ystem
. Implement operating system as a collection of system processes . 1seful in multi-processor or multicomputer environment . /ecessary when a micro-kernel architecture is employed,

ecurity Issues - Intrusion


Ob*ective of intruder is to gain access to the system or to increase the range of privileges accessible on a system 'ypes of intruders3
. "as!uerader 4outsider5 . "isfeasor 4insider5 . Clandestine user 4insider or outsider5

ecurity Issues . "alicious oftware


'ypes of malicious programs3
. 'hose that need a host program 4e,g, viruses5
2ragments of programs that cannot e$ist independently of some application program, utility, or system program

. Independent 4e,g, tro*an horses5


elf-contained programs that can be scheduled and run by the operating system

Countermeasures
Inrusion Detection ystems %uthentication
. ensors . %naly)ers

%ccess Control 2irewalls

. omething the individual knows . omething the individual possesses . omething the individual is 4static biometrics5 . omething the individual does 4dynamic biometrics5

1/I: ;&< Process "anagement


"ost of the operating system e$ecutes within the environment of a user process

1/I: Process tates

1ni$ Process
1nder 1/I:, a process consists of3
. 1ser-level Conte$t
%ll memory regions 4code, data, shared, stack5

. &egister Conte$t
CP1 register contents, including PC

. ystem-level Conte$t
Process-table data 1 4user5 area Per process region table 4virtual to physical address mapping, including permission flags5 7ernel stack

Process states as reported by ps


D 3 1ninterruptible sleep 4usually I(O5 & 3 &unning or runnable 4on run !ueue5 3 Interruptible sleep 4waiting for an event to complete5 ' 3 topped, either by a *ob control signal or because it is being traced, 9 3 paging 4not valid since the =,>,$$ kernel5 : 3 dead 4should never be seen5 ? 3 Defunct 4@)ombie@5 process, terminated but not reaped by its parent,

2ields reported by ps
1ID 3 user ID PID 3 Process ID PPID 3 Parent Process ID P&I 3 priority /I 3 nice, % value used to calculate priority ; ? 3 ;irtual "emory i)e &# 4or & 5 3 resident memory si)e

2ields reported by ps
9CA%/ 3 waiting channel ''B 3 the name of the terminal that a process is attached to for performing console I(O '%' 3 status 'I"# 3 total e$ecution time CO""%/D 3 name of e$ecutable

&unning top

1ni$ Process 'ree

'he fork45 mechanism


Aistorically the first approach for implementing mutliprogramming, 9hen a process e$ecutes the fork function, the O creates a copy of the processes memory, complete with all the code and data 4e$cept shared memory5, 'he copy is the child and the original the parent in this operation, #$ample3
#include <unistd.h> . . . pid_t childID; childID = fork();

'he fork45 mechanism 4cont,5


pid_t childID; childID = fork(); if(childID==0) Child pid_t childID; { childID = fork(); printf("Child proc.\n"); if(childID==0) ... { } printf("Child proc.\n"); else ... { } printf("Parent\n"); else ... { } printf("Parent\n"); ... }

Parent

Das könnte Ihnen auch gefallen