Certification Linux LPI/Administrateur système débutant/Examen 101/GNU et commandes Unix/Créer, surveiller et terminer des processus

Leçons de niveau 14
Une page de Wikiversité, la communauté pédagogique libre.

Image logo Il a été demandé de traduire cette page depuis Image logo

Début de la boite de navigation du chapitre
Créer, surveiller et tuer des tâches
Icône de la faculté
Chapitre no 6
Leçon : GNU et commandes Unix
Chap. préc. :Utiliser les flux, les tuyeaux (pipes) et les re-directions
Chap. suiv. :Modifier les priorités d'exécution des processus
fin de la boite de navigation du chapitre
En raison de limitations techniques, la typographie souhaitable du titre, « GNU et commandes Unix : Créer, surveiller et tuer des tâches
Certification Linux LPI/Administrateur système débutant/Examen 101/GNU et commandes Unix/Créer, surveiller et terminer des processus
 », n'a pu être restituée correctement ci-dessus.

Objectifs[modifier | modifier le wikicode]

Description: Les candidats devraient pouvoir gérer les processus.

Cela comprend:

  • La compréhension de la façon d'exécuter un job en tache de fond ou non (foreground and background);
  • De modifier leur statut (background vers foreground et vice versa);
  • Démarrer un processus qui s'exécutera sans connexion à un terminal et signaler au programme de continuer après le logout.

Les taches comprennent aussi la gestion des processus actifs:

  • En sélectionnant et triant les processus pour visualisation;
  • En envoyant des signaux au processus;
  • En tuant des processus;
  • En identifiant et tuant des applications X qui ne se sont pas arretées alors que la session X est close.

Key files terms and utilities include:
&
bg
fg
jobs
kill
nohup
ps
top

Créer des processus[modifier | modifier le wikicode]

A running application is a process. Every processes have: A process ID. A parent process ID. A current directory PWD. A file descriptor table. A program which it is executing. Environment variables, inherited from its parent process. Stdin, stdout, and stderr Other

Bash is a program that when it is executed becomes a process. Each time you execute a command in a shell a new process is created. Except for the built-in shell command. They run in the shell context. Use type to check if a command is a built-in shell command.

Example type cp ls which type Monitor processes Once the system is up and running from a terminal it is possible to see which processes are running with the ps program. To display a long format of all the processes in the system, do:

ps -Al
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
004 S     0     1     0  0  80   0 -   112 do_sel ?        00:00:04 init
004 S     0   381     1  0  80   0 -   332 do_sel ?        00:00:00 dhcpcd
006 S     0  1000     1  0  80   0 -   339 do_sel ?        00:00:00 inetd
044 R     0  1524  1222  0  79   0 -   761 -      pts/3    00:00:00 ps

The ps program will display all the processes running and their PID numbers and other information. To see a long format of the processes in your login session, do a:

ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
000 S   500  1154  1139  0  80   0 -   724 wait4  pts/1    00:00:00 bash
002 S   500  1285  1283  0  77   0 - 24432 wait_f pts/1    00:00:00 soffice.bin
040 R   500  1442  1435  0  79   0 -   768 -      pts/4    00:00:00 ps
F: Process Flags 002: being created, 040: forked but didn't exec, 400: killed by a signal.
S: Process States: R: runnable, S: sleeping, Z: zombie
UID: User ID, PID: Process ID, PPID: Parent Process ID, C: Scheduler, PRI: priority
NI: Nice value, SZ: size of routine, WCHAN: name of routine

Surveiller des processus[modifier | modifier le wikicode]

To monitor the processes in real-time, use top. top

 9:20am  up  2:48,  4 users,  load average: 0.15, 0.13, 0.09

78 processes: 75 sleeping, 3 running, 0 zombie, 0 stopped CPU states: 15.3% user, 0.3% system, 0.0% nice, 84.2% idle Mem: 254896K av, 251204K used, 3692K free, 0K shrd, 27384K buff Swap: 514072K av, 0K used, 514072K free 120488K cached

 PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
1517 rarrigon   0   0 40816  39M 17372 R    15.0 16.0   2:59 mozilla-bin
1727 rarrigon  19   0   988  988   768 R     0.3  0.3   0:00 top
   1 root      20   0   220  220   188 S     0.0  0.0   0:04 init
   2 root      20   0     0    0     0 SW    0.0  0.0   0:00 keventd

RSS: The total amount of physical memory used by the task. SHARE: The amount of shared memory used by the task. %CPU: The task's share of the CPU time. %MEM: The task's share of the physical memory. Once top is running it is also possible to execute interactive commands: Type N to sort tasks by pid. Type A to sort tasks by age (newest first). Type P to sort tasks by CPU usage. Type M to sort tasks by memory usage. Type k to kill a process (prompted for pid).

Terminer des processus[modifier | modifier le wikicode]

The ps program will display all the processes running and their PID numbers. Once the PID is known, it is possible to send signals to the process. SIGSTOP to stop a process. SIGCONT to continue a stopped process. SIGKILL to kill a process.

The program to send a signal to a process is called kill.

kill -SIGKILL [pid]
kill -63 [pid]
kill -l

By default a process is started in foreground and it is the only one to receive keyboard input. Use CTRL+Z to suspend it.

To start a process in backgroud use the &.

bash &
xeyes &

Job control

In a bash process it is possible to start multiple jobs. The command to manipulate jobs are:

jobs   # List all the active jobs
bg %job  # Resume job in background
fg %job  # Resume job in foreground
kill %job # Kill background job

When bash is terminated all processes that have been started from the session will receive the SIGHUP signal. This will by default terminate the process.

To prevent the termination of a process, the program can be started with the nohup command.

nohup mydaemon

Solution des exercices[modifier | modifier le wikicode]

1. La ligne à ajouter dans /etc/fstab est

/dev/fd0 /media/floppy auto rw,user,noauto 0 0