if 110 –les processus - laurent réveillère · 2019. 9. 11. · if 110 –les processus...

55
Laurent Réveillère Université de Bordeaux [email protected] http://www.reveillere.fr/ IF 110 – Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

Upload: others

Post on 19-Mar-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

LaurentRéveillère

Université deBordeaux

[email protected]://www.reveillere.fr/

IF110– LesProcessus

D’aprèslecoursd’introductionauxsystèmesd’exploitationdeTélécomSudParis

Page 2: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

2

Présentationducours

q Contexte:Ø Desdizainesdeprocessuss’exécutentsimultanémentsurune

machine

q Objectifs:Ø Savoirobserverlesprocessuss’exécutantsurunemachineØManipulerunprocessusencoursd’exécutionØ Comprendrecommentsontordonnancéslesprocessus

q Notionsclés:Ø Arborescencedeprocessus,étatsd’unprocessus,

ordonnancement

Page 3: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

3

Notiondeprocessus

q Processus=programmeencoursd'exécutionØ Unespacemémoire+contexted'exécution(fichiersouverts,

etc.)

q CaractéristiquesstatiquesØ PID :Process Identifier(identifieleprocessus)Ø PPID :ParentProcessusIdentifier(identifieleparent)Ø UtilisateurpropriétaireØ Droitsd'accèsauxressources(fichiers,etc.)

q CaractéristiquesdynamiquesØ Priorité,environnementd’exécution,etc.Ø Quantitéderessourcesconsommées(tempsCPU,etc.)

Page 4: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

4

Plan

1. Observerunprocessus

2. Processusenavantetarrièreplan

3. Cycledevied’unprocessus

4. Variablesetprocessus

5. Gestiondesprocessusdanslesystèmed’exploitation

Page 5: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

5

Arborescencedeprocessus

q ChaqueprocessuspossèdeunprocessusparentØ Sauflepremierprocessus(systemd ouinit,PID=1)⇒ arborescencedeprocessus

q Deuxtypesdeprocessus:Ø Processusutilisateurs(attachésàunterminal)Ø Daemons :processusquiassurentunservice(détachésdetout

terminal)systemd

gnome sshd cron

terminal chrome

bash

emacs pstree

updatedb

Page 6: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

6

Observerlesprocessus

q ps :affichelesprocessuss’exécutantàuninstantdonné

$ ps -lF S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD0 S 1000 22995 1403 0 80 0 - 6285 - pts/1 00:00:00 bash0 S 1000 29526 22995 0 80 0 - 128631 - pts/1 00:00:05 emacs0 S 1000 29826 22995 0 80 0 - 51571 - pts/1 00:00:00 oosplash0 S 1000 29843 29826 1 80 0 - 275029 - pts/1 00:00:48 soffice.bin0 R 1000 30323 22995 0 80 0 - 2790 - pts/1 00:00:00 ps

Page 7: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

7

Observerlesprocessus(suite)

q pstree :affichel'arborescencedesprocessus

$ pstree -pAsystemd(1)-+-ModemManager(535)-+-{gdbus}(675)

| `-{gmain}(580)|-NetworkManager(552)-+-dhclient(27331)| |-{NetworkManager}(673)| |-{gdbus}(756)| `-{gmain}(733)|-acpid(692)|-konsole(1403)-+-bash(22995)-+-emacs(29526)-+-{dconf worker}(29529)

| | |-{gdbus}(29528)| | `-{gmain}(29527)| `-pstree(30412)`-{QProcessManager}(1411)

Page 8: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

8

Observerlesprocessus(suite)

8

q top :affichedynamiquementdesprocessus$ toptop - 15:52:18 up 5 days, 2:04, 3 users, load average: 0,19, 0,12, 0,13Tasks: 176 total, 1 running, 175 sleeping, 0 stopped, 0 zombie%Cpu(s): 6,0 us, 1,3 sy, 0,1 ni, 92,5 id, 0,1 wa, 0,0 hi, 0,0 si, 0,0 stKiB Mem: 8099392 total, 5840956 used, 2258436 free, 494524 buffersKiB Swap: 10157052 total, 0 used, 10157052 free. 3114404 cached Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 866 root 20 0 731892 377196 346672 S 6,4 4,7 21:01.97 Xorg

1375 trahay 9 -11 651480 11108 8052 S 6,4 0,1 23:23.48 pulseaudio1 root 20 0 176840 5420 3144 S 0,0 0,1 0:02.57 systemd2 root 20 0 0 0 0 S 0,0 0,0 0:00.01 kthreadd3 root 20 0 0 0 0 S 0,0 0,0 0:04.34 ksoftirqd/0 5 root 0 -20 0 0 0 S 0,0 0,0 0:00.00 kworker/0:0H 7 root 20 0 0 0 0 S 0,0 0,0 0:30.37 rcu_sched

Page 9: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

9

Variablesrelativesauxprocessus

q Chaque processusbash,ycomprislesscripts,définissent:Ø $$ :PID dubash courantØ $PPID :PID duparentdubash courant

$ echo $$20690$ echo $PPID20689$

Page 10: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

10

Variablesrelativesauxprocessus

q Chaque processusbash,ycomprislesscripts,définissent:Ø $$ :PID dubash courantØ $PPID :PID duparentdubash courant

$ echo $$20690$ echo $PPID20689$ ps -p 20689,20690 PID TTY TIME CMD

20689 ?? 0:11.69 xterm -r20690 ttys004 0:01.32 bash$

Page 11: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

11

Détaild'unprocessus

q /proc/$PID/ contient :Ø cmdline :textedelalignedecommandeayantlancéleprocessusØ exe :lienverslefichierexécutableduprogrammeØ environ :contenudel'environnementØ fd :liensverslesfichiersouvertsØ …

$ ls /proc/29526attr coredump_filter gid_map mountinfo oom_score sessionid taskautogroup cpuset io mounts oom_score_adj smaps timersauxv cwd limits mountstats pagemap stack uid_mapcgroup environ loginuid net personality stat wchanclear_refs exe map_files ns projid_map statmcmdline fd maps numa_maps root statuscomm fdinfo mem oom_adj sched syscall

Page 12: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

12

Plan

1. Observerunprocessus

2. Processusenavantetarrièreplan

3. Cycledevied’unprocessus

4. Variablesetprocessus

5. Gestiondesprocessusdanslesystèmed’exploitation

Page 13: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

13

Processusenavant-plan

q Pardéfaut,unecommandes'exécuteenavant-plan(enanglais,foreground)Øbash créeunprocessusenfantetattendqu'iltermineØ Leprocessusenfantexécuteleprogramme

$terminal

bash

Page 14: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

14

Processusenavant-plan

q Pardéfaut,unecommandes'exécuteenavant-plan(enanglais,foreground)Øbash estbloquétantqueleprocessusfilss'exécute

$ xeyesterminal

bash (bloqué)

xeyes

Page 15: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

15

Processusenavant-plan

q Pardéfaut,unecommandes'exécuteenavant-plan(enanglais,foreground)ØQuandleprocessusfilssetermine,bash reprendsonexécution

$ xeyes$ terminal

bash

Page 16: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

16

Processusen arrière-plan

q Pourexécuterunecommandearrière-plan(enanglais,background)ØTerminerlacommandepar« & »

$terminal

bash

Page 17: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

17

Processusen arrière-plan

q Commandeenarrière-plan (enanglais,background)Øbash créeunenfantetn'attendpasqu'ilsetermineØbash affichelenumérodejob(JobID)etlePIDdufilsØ Leprocessusenfantexécuteleprogramme

$ xeyes &[1] 35794 $

terminal

xeyes

bash

Page 18: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

18

Processusen arrière-plan

q Commandeenarrière-plan (enanglais,background):Øbash etleprocessusfilss'exécutentenparallèleØbash peutdoncexécuterd'autrescommandes

$ xeyes &[1] 35794 $ grep c bjr.txtcoucou

terminal

xeyes

bash

grep

Page 19: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

19

Processusen arrière-plan

q Commandeenarrière-plan (enanglais,background):Øbash etleprocessusfilss'exécutentenparallèleØbash peutdoncexécuterd'autrescommandes

$ xeyes &[1] 35794 $ grep c bjr.txtcoucou$

terminal

xeyes

bash

Page 20: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

20

Processusen arrière-plan

q Commandeenarrière-plan (background):ØQuandlefilssetermine,lesystèmed’exploitationinformebash

terminal

bash

$ xeyes &[1] 35794 $ grep c bjr.txtcoucou$[1]+ Done xeyes$

JobID

Page 21: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

21

PIDdudernierprocessuslancé

q LePIDdudernierprocessuslancéestdanslavariable$!

$ xeyes &[1] 35794 $ echo $!35794$

Page 22: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

22

Plan

1. Observerunprocessus

2. Processusenavantetarrièreplan

3. Cycledevied’unprocessus

4. Variablesetprocessus

5. Gestiondesprocessusdanslesystèmed’exploitation

Page 23: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

23

Commandesetprocessus

q ChaquecommandecréeunprocessusSaufpourlescommandesinternesquisontdirectementinterprétéesparbash (exit,source…)

#! /bin/bash

head –n 30 itineraire > debut_itigrep plage debut_iti> baignadecut –d’ ’ –f3 baignade > tresorrm baignade

vacances.sh

bash vacances.sh (8281)

head(8282)

grep(8287)

cut(8293)

rm(8297)

Page 24: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

24

Scriptsetprocessus

q Pardéfaut,unscriptestlancédansunprocessusenfant

#! /bin/bashif [ $1 –eq 0 ] || [ $1 –eq 1 ]; then

echo 1else

n=$1fib1=$(./fibo $(expr $n – 1))fib2=$(./fibo $(expr $n - 2))echo $(expr $fib1 + $fib2 )

fi

fibo

bash (8281)

./fibo 3(16837)

./fibo 2(16838) ./fibo 1(16841)

./fibo 1(16839) ./fibo 0(16840)

Page 25: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

25

Scriptsetprocessus

q Onpeutaussichargerunscriptdansleprocessusbash courantavecsource ./script.sh

Page 26: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

26

Suspendreunprocessus

q Suspendreunprocessusenavant-plan :control+zØ Leprocessusestplacé« enattente »

q ReprendreunprocessusenattenteØPourlemettreenavant-plan :fg (foreground)ØPourlemettreenarrière-plan :bg (background)

Page 27: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

27

q Unprocessussetermines’ilatteintsadernièreinstruction

q Ous’ilappelleexitq Ous’ilreçoitunsignal(voircourssuivant)

Ø control-c :tueleprocessusenavantplan(avecSIGINT)Ø kill oukillall :tueunprocessus(avecSIGTERM)

» kill %JobID :tueleprocessusdenumérodejobJobID» kill PID :tueleprocessusd’identifiantPID» killall prog :tuetouslesprocessusdontlecheminduprogrammeestprog

Ø Remarque:vousverrezplustardquelesprocessuspeuventrésisteràcontrol-c,kill oukillall.Sic’estlecas,ajoutez-9(SIGKILL)aprèskill/killlall pourforcerleurmort

Suppressiond'unprocessus

Page 28: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

28

Étatsd'unprocessus

Enexécution

Enattente

Terminé

bg, fg, kill

Terminaison,exit, kill,control-C

control+z

création destruction

Page 29: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

29

Attendrelafind’unprocessus

q Lacommandewait permetd’attendrelafind’unfilsØwait sansargument:attendlafindetouslesfilsØwait %jobid1 %jobid2…ouwait pid1 pid2…:attendlafindesprocessuspassésenargument

Page 30: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

30

Attendrelafind’unprocessus

tempsbash

Processusenexécution

$

Page 31: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

31

Attendrelafind’unprocessus

temps

xeyes

Créationdeprocessus

bash

$ xeyes &$

Processusenexécution

Page 32: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

32

Attendrelafind’unprocessus

temps

Créationdeprocessus

bash

grepxeyes

Processusenattente

$ xeyes &$ grep reveillere /etc/passwd

Processusenexécution

Page 33: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

33

Attendrelafind’unprocessus

temps

CréationdeprocessusNotificationdefindeprocessus

bash

grepxeyes

Processusenattente

$ xeyes &$ grep reveillere /etc/passwdreveillere:x:501:20::/home/reveillere:/bin/bash$

Processusenexécution

Page 34: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

34

Attendrelafind’unprocessus

temps

CréationdeprocessusNotificationdefindeprocessus

bash

grepxeyes

Processusenattente

$ xeyes &$ grep reveillere /etc/passwdreveillere:x:501:20::/home/reveillere:/bin/bash$ wait

Processusenexécution

Page 35: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

35

Attendrelafind’unprocessus

$ xeyes &$ grep reveillere /etc/passwdreveillere:x:501:20::/home/reveillere:/bin/bash$ wait[1]+ Done xeyes$

temps

grep

CréationdeprocessusNotificationdefindeprocessus

bash

xeyes

ProcessusenattenteProcessusenexécution

Page 36: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

36

Plan

1. Observerunprocessus

2. Processusenavantetarrièreplan

3. Cycledevied’unprocessus

4. Variablesetprocessus

5. Gestiondesprocessusdanslesystèmed’exploitation

Page 37: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

37

Variablesbash etprocessus

q Unevariableesttoujourslocaleàunprocessus⇒ lesmodificationssonttoujourslocales

q UnevariablepeutêtreexportéechezunenfantØ Lavariableetsavaleursontrecopiéeschezl’enfantàlacréationØ Lesvariablesdupèreetdufilssontensuiteindépendantes

Ø Pardéfautunevariablen’estpasexportée

ØMarquerunevariablecommeexportée:export varØ Arrêterd’exporterunevariable:unset var

(détruitaussilavariable)

Page 38: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

38

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 39: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

39

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$ ./variable.sha: b: existe$

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 40: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

40

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$ ./variable.sha: b: existe$ export a$

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 41: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

41

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$ ./variable.sha: b: existe$ export a$ ./variable.sha: existeb: existe$

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 42: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

42

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$ ./variable.sha: b: existe$ export a$ ./variable.sha: existeb: existe$ echo "a: $a - b: $b"a: existe - b: $

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 43: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

43

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$ ./variable.sha: b: existe$ export a$ ./variable.sha: existeb: existe$ echo "a: $a - b: $b"a: existe - b: $ ./variable_exortee.sha: existeb: existe$

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 44: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

44

#! /bin/bash

export bb="existe"echo "a: $a"echo "b: $b"

Portéedesvariables

$ a="existe"$ ./variable.sha: b: existe$ export a$ ./variable.sha: existeb: existe$ echo "a: $a - b: $b"a: existe - b: $ ./variable_exortee.sha: existeb: existe$ echo "b: $b"b: $

#! /bin/bash

b="existe"echo "a: $a"echo "b: $b"a="autre chose"

variable.sh

variable_exportee.sh

Page 45: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

45

Variablesd’environnement

q Unevariableexportées’appelleunevariabled’environnement

q Certainesvariablessontsouventdansl’environnement:ØHOME :cheminabsoludurépertoiredeconnexion

» cd ,cd ~ etcd $HOME sontdescommandeséquivalentesØPS1 :prompt(pardéfaut$)ØPATH :listedesrépertoiresderecherchedescommandes

» Rappel:entrechaquechemin,séparateur« : »

Page 46: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

46

Plan

1. Observerunprocessus

2. Processusenavantetarrièreplan

3. Cycledevied’unprocessus

4. Variablesetprocessus

5. Gestiondesprocessusdanslesystèmed’exploitation

Page 47: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

47

Partagederessources

Proc1

Proc2

Proc3

Proc4

processeurdisquedur mémoire

Systèmed’exploitation

q RessourcespartagéesparlesprocessusØ CPU(cœurd’unprocesseur)Ø MémoireØ Entrées-sorties

q GestionparleSystèmed'ExploitationØ ExclusionmutuelleØ Contrôledel'accèsaumatérielØ Droitsd'accèsØ Non-dépassement deslimites

Page 48: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

48

PartageduCPU

P1 P2 P3 P2 P3Processusexécuté

Processusprêt

P2P3

P2P3

P1P3 P2

P1 P1P3 P2

P1

t

q Àuninstantdonné,leCPUn'exécutequ'unprocessusØ Lesautresprocessusattendent

q L'ordonnanceur partageleCPUpar« quantumdetemps »(enanglais,timeslice)Ø Àlafindutimeslice,l’ordonnanceur préempteleprocessus

s’exécutantetchoisitunautreprocessus

P1

Page 49: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

49

PartageduCPUetentrées/sorties

P1 P2 P3 P1 P2P3Processusexécuté

Processusprêt

P2P3

P2

P3P1P3

P2

P1 P1P3

P2

P1

Processusenattente

P1

P2P1

P3P2

t

q Entrées/sorties⇒ attented'uneressource(disque,carteréseau,écran,etc.)

q LibérationduCPUenattendantlaressource

Page 50: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

50

Étatsd'unprocessus

Prêt

Enattente

Actif

terminaison(kill,exit,fin)

acquisitiondelaressource(oukill pourcertaines

attentes)

élection

création

destruction

préemption

attented'uneressource

Terminé

Page 51: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

51

Commutationdeprocessus

¢ Lacommutationalieulorsdel'électiond'unprocessus:• Sauvegardeducontexteduprocessusévincé• Chargementducontexteduprocessusélu

¢ Contexte :ensembledesinfosassociéesauprocessus• Valeurdesregistres• Informationsmémoire(emplacement,etc.)

Mem

P1 P2Processusexécuté

t

P1

Sauvegardeducontexte

Restaurationducontexte

Page 52: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

52

Ordonnancementdeprocessus

¢ Unefiled’attentedesprocessusprêtsparniveaudepriorité

¢ L’ordonnanceurchoisitplussouventlesprocessusdefortepriorité

¢ Ajustementdelaprioritéd’unprocessusaucourtdesonexécution

¢ Exempled'algorithmed'ordonnancement• Choisirunprocessusdelafiled’attentenon

videdeplushautepriorité• Siunprocessusconsommetoutson

timeslice :priorité--• Régulièrement :priorité++ pourles

processusnonélus

entréedesprocessus

filed'attente0

filed'attente1

filed'attentenprioritéTerminaisonduprocessus

Page 53: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

53

Changerlaprioritéd’unprocessus

q Possibilitédechangermanuellementlaprioritéd’unprocessusØExemple:baisserlaprioritéd’unprogrammequiindexelecontenud’undisquedur

q LancerunprogrammeavecunecertaineprioritéØ$ nice –n priorité commande

q Changerlaprioritéd’unprocessusdéjàlancéØ$ renice –n priorité PID

Page 54: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

54

q Accèsconcurrentàuneressourcegéréeparl'OSØ Disquedur,imprimante,sortieduterminal,…

q L'OSassurel'exclusionmutuelleØ Àtoutmoment,seulunprocessusmanipulelaressource

Introductionàlaconcurrence

$ ./do_ping.sh &./do_pong.shpingpongpingpongpingpongpingpongpongpongpingpingpingpingpong

P1 P2ping pong

P1 P2ping pong

P1ping

P1ping

P2pong

t

P1ping

#!/bin/bashwhile true; do

echo pongdone

do_pong.sh

#!/bin/bashwhile true; do

echo pingdone

do_ping.sh

Page 55: IF 110 –Les Processus - Laurent Réveillère · 2019. 9. 11. · IF 110 –Les Processus D’après le cours d’introduction aux systèmes d’exploitation de Télécom SudParis

55

Conclusionq Conceptsclés

ØProcessus» Caractéristiquesstatiquesetdynamiques» Processusparent,processusenfant» Exécutionenavant-plan,arrière-plan,suspension/reprisedeprocessus

ØOrdonnancementdeprocessus» Quantumdetemps,préemption» changementdecontexte

q CommandesclésØps, pstree, topØCTRL+Z, fg, bg

ØCTRL+C, kill, killall