tech:processus
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:processus [2025/10/17 18:43] – Jean-Baptiste | tech:processus [2026/06/08 21:22] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Les Processus sous Linux | ||
| + | |||
| + | Voir aussi : | ||
| + | * [[Notes atop]] | ||
| + | * [[process_audit_quand_strace_n_est_pas_la]] | ||
| + | * [[Linux - Process - nohup ne fonctionne pas]] | ||
| + | * `/ | ||
| + | |||
| + | Tuer tous les processus d'un utilisateur | ||
| + | ~~~bash | ||
| + | pkill -u plop | ||
| + | ~~~ | ||
| + | |||
| + | Appels système au noyaux et signaux | ||
| + | ~~~bash | ||
| + | strace -p $PID | ||
| + | strace -f -e trace=file $CHEMIN_EXE 2>&1 | grep '/ | ||
| + | ~~~ | ||
| + | |||
| + | La table des processus | ||
| + | ~~~bash | ||
| + | ps -ef | grep $PID | ||
| + | # ps -Aww -o pid, | ||
| + | ~~~ | ||
| + | |||
| + | 2em colone => PID | ||
| + | 3em colone => PPID | ||
| + | |||
| + | |||
| + | |||
| + | Qui a lancé ce processus ? PPID ? Service ? | ||
| + | ~~~bash | ||
| + | journalctl _PID=2636 -o json-pretty | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Que fait TTY1 ? | ||
| + | |||
| + | ~~~bash | ||
| + | peekfd -cn8 $(ps -t tty1 | grep -v login | sort -nr | head -1 | awk ' | ||
| + | ~~~ | ||
| + | |||
| + | ### ProcFS | ||
| + | Voir egalement /proc/$PID/ | ||
| + | Voir `man proc` ou `man procfs` | ||
| + | |||
| + | #### Cacher /proc et la table des processus aux utilusateurs : | ||
| + | |||
| + | Avec Grsecurity | ||
| + | Ou | ||
| + | en en remontant /proc | ||
| + | [[http:// | ||
| + | [[http:// | ||
| + | [[http:// | ||
| + | |||
| + | Modifier la ligne */proc* dans / | ||
| + | Si aucune ligne ne correspond, ajouter la | ||
| + | `fstab` | ||
| + | ~~~ | ||
| + | proc /proc | ||
| + | ~~~ | ||
| + | Pour appliquer la modif sans redemarrer : | ||
| + | |||
| + | ~~~bash | ||
| + | mount -o remount /proc/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Audit process | ||
| + | |||
| + | Voir execsnoop et autres : | ||
| + | [[https:// | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## Arrière plan | ||
| + | |||
| + | Using the [Job Control](http:// | ||
| + | |||
| + | * Ctrl+Z to stop (pause) the program and get back to the shell. | ||
| + | * bg to run it in the background. | ||
| + | * disown -h [job-spec] where [job-spec] is the job number (like %1 for the first running job; find about your number with the jobs command) so that the job isn't killed when the terminal closes. | ||
| + | |||
| + | Source : [[http:// | ||
| + | |||
| + | |||
| + | |||
| + | `info coreutils 'nohup invocation`' | ||
| + | |||
| + | Voir : | ||
| + | |||
| + | * nohup $EXE | ||
| + | * $EXE & | ||
| + | * ctrl + z | ||
| + | * bg | ||
| + | * fg | ||
| + | * pstree | ||
| + | * ps | ||
| + | * setsid | ||
| + | * runit / shpst | ||
| + | * trap | ||
| + | |||
| + | ~~~ | ||
| + | # kill -l | ||
| + | 18) SIGCONT 19) SIGSTOP | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | Exemple | ||
| + | |||
| + | |||
| + | |||
| + | ### Exemple | ||
| + | |||
| + | |||
| + | ~~~ | ||
| + | # jobs | ||
| + | [1]+ Stoppé | ||
| + | [2]- En cours d' | ||
| + | |||
| + | jobs %% | ||
| + | jobs %1 | ||
| + | ~~~ | ||
| + | |||
| + | Stopper le job1 | ||
| + | ~~~bash | ||
| + | kill -19 %1 | ||
| + | ~~~ | ||
| + | |||
| + | Lancer le job2 une fois le job1 terminé | ||
| + | ~~~bash | ||
| + | wait %2; kill -18 %1 | ||
| + | ~~~ | ||
| + | |||
| + | http:// | ||
| + | |||
| + | ~~~bash | ||
| + | sleep $(( 60 * 3 )) ; echo "Les œufs sont prêt" | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | sleep $(( 60 * 3 )) && echo "Les œufs sont prêt" | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | sleep $(( 60 * 3 )) & | ||
| + | wait $! | ||
| + | echo "Les œufs sont prêt" | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | sleep $(( 60 * 3 )) | ||
| + | ~~~ | ||
| + | **[Ctrl] + [Z]** | ||
| + | ~~~bash | ||
| + | fg && echo "Les œufs sont prêt" | ||
| + | ~~~ | ||
| + | |||
| + | ## Autres | ||
| + | |||
| + | Voir atop, htop | ||
| + | Voir cgroup | ||
| + | |||
| + | ## kthreadd | ||
| + | |||
| + | Voir https:// | ||
| + | |||
| + | ~~~ | ||
| + | # ps -ef | head -40 | ||
| + | UID PID PPID C STIME TTY TIME CMD | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root | ||
| + | root 10 | ||
| + | root 11 | ||
| + | root 12 | ||
| + | root 13 | ||
| + | root 14 | ||
| + | root 15 | ||
| + | root 16 | ||
| + | root 17 | ||
| + | root 18 | ||
| + | root 19 | ||
| + | root 20 | ||
| + | root 21 | ||
| + | root 22 | ||
| + | root 23 | ||
| + | root 24 | ||
| + | root 25 | ||
| + | root 26 | ||
| + | root 27 | ||
| + | root 28 | ||
| + | root 29 | ||
| + | root 30 | ||
| + | root 31 | ||
| + | root 32 | ||
| + | root 33 | ||
| + | root 34 | ||
| + | ~~~ | ||
| + | |||
| + | Nous pouvons constater immédiatement quatre choses : | ||
| + | |||
| + | 1. Les processus ' | ||
| + | 2. Le process père est [kthreadd] (PPID 2) | ||
| + | 3. Nous avons 8 processus : migration/ | ||
| + | 4. Ces processus sont démarrés depuis le démarrage du système d' | ||
| + | |||
| + | ~~~ | ||
| + | $ LANG=C man ps | ||
| + | " | ||
| + | ~~~ | ||
| + | |||
| + | ## Les zombies | ||
| + | |||
| + | Voir : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ### Tuer les zombies ! | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | Also known as “defunct” or “dead” process – In simple words, a Zombie process is one that is dead but is present in the system’s process table. Ideally, it should have been cleaned from the process table once it completed its job/ | ||
| + | |||
| + | In a just (Linux) world, a process notifies its parent process once it has completed its execution and has exited. Then the parent process would remove the process from process table. At this step, if the parent process is unable to read the process status from its child (the completed process), it won’t be able to remove the process from memory and thus the process being dead still continues to exist in the process table – hence, called a Zombie! | ||
| + | |||
| + | In order to kill a Zombie process, we need to identify it first. The following command can be used to find zombie processes: | ||
| + | |||
| + | ~~~bash | ||
| + | ps aux | egrep " | ||
| + | ~~~ | ||
| + | |||
| + | Z in the STAT column and/or [defunct] in the last (COMMAND) column of the output would identify a Zombie process. | ||
| + | |||
| + | Now practically you can’t kill a Zombie because it is already dead! What can be done is to notify its parent process explicitly so that it can retry to read the child (dead) process’s status and eventually clean them from the process table. This can be done by sending a SIGCHLD signal to the parent process. The following command can be used to find the parent process ID (PID): | ||
| + | |||
| + | ~~~bash | ||
| + | ps -o ppid= <Child PID> | ||
| + | ~~~ | ||
| + | |||
| + | Once you have the Zombie’s parent process ID, you can use the following command to send a SIGCHLD signal to the parent process: | ||
| + | |||
| + | ~~~bash | ||
| + | kill -s SIGCHLD <Parent PID> | ||
| + | ~~~ | ||
| + | |||
| + | However, if this does not help clearing out the Zombie process, you will have to kill or restart its parent process OR in case of a huge surge in Zombie processes causing or heading towards system outage, you will have no choice but to go for a system reboot. The following command can be used to kill its parent process: | ||
| + | |||
| + | ~~~bash | ||
| + | kill -9 <Parent PID> | ||
| + | ~~~ | ||
| + | |||
| + | Note that killing a parent process will affect all of its child processes, so a quick double check will be helpful to be safe. Alternatively, | ||
| + | |||
| + | |||
| + | ## Strace | ||
| + | |||
| + | Voir : https:// | ||
| + | |||
| + | Exemple : | ||
| + | |||
| + | ~~~bash | ||
| + | strace -e trace=network -f iceweasel http:// | ||
| + | |||
| + | strace -ttfv -s128 -o / | ||
| + | |||
| + | strace -f -p $(pidof mariadbd) --trace=sendto, | ||
| + | |||
| + | vimdiff <(cat plop.log | sed -e ' | ||
| + | ~~~ | ||
| + | |||
