====== Linux ====== ===== Processus ===== \\ ==== Voir les processus courants ==== **Commande ''ps''** (formation㉿lubuntu01)[~]$ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 10:03 ? 00:00:02 /sbin/init splash root 2 0 0 10:03 ? 00:00:00 [kthreadd] root 3 2 0 10:03 ? 00:00:00 [rcu_gp] ... (formation㉿lubuntu01)[~]$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 100644 11336 ? Ss 10:03 0:02 /sbin/init splash root 2 0.0 0.0 0 0 ? S 10:03 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 10:03 0:00 [rcu_gp] ... (formation㉿lubuntu01)[~]$ ps -fu formation UID PID PPID C STIME TTY TIME CMD formati+ 854 1 0 10:03 ? 00:00:00 /lib/systemd/systemd --user formati+ 855 854 0 10:03 ? 00:00:00 (sd-pam) formati+ 861 854 0 10:03 ? 00:00:00 /usr/bin/pipewire formati+ 862 854 0 10:03 ? 00:00:00 /usr/bin/pipewire-media-session formati+ 863 854 0 10:03 ? 00:00:00 /usr/bin/pulseaudio --daemonize=no --log-target=journal formati+ 878 854 0 10:03 ? 00:00:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --syst formati+ 924 797 0 10:03 ? 00:00:00 sshd: formation@pts/0 formati+ 925 924 0 10:03 pts/0 00:00:00 -bash ... **Commande ''pstree''** (visualisation des dépendances) (formation㉿lubuntu01)[~]$ ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 1000 925 924 0 80 0 - 2875 do_wai pts/0 00:00:00 bash 0 T 1000 1335 925 0 80 0 - 2362 do_sig pts/0 00:00:00 nano 0 T 1000 1343 925 0 80 0 - 2362 do_sig pts/0 00:00:00 nano 0 R 1000 1900 925 0 80 0 - 3168 - pts/0 00:00:00 ps (formation㉿lubuntu01)[~]$ pstree 925 bash─┬─2*[nano] └─pstree \\ ==== Voir les processus actifs en "live" ==== ^ Solaris | ''prstat'' | ^ Linux | ''top'' , ''htop'' | \\ ==== Gestion des commandes en tâche de fond ==== Lancer une commande en tâche de fond en mettant le caractère ''&'' en fin de ligne ping localhost & Lancer une commande en tâche de fond, isolée du shell courant : ''nohup'' nohup ping localhost & Lister les programmes en tâche de fond : ''jobs'' ou ''bg'' (formation㉿lubuntu01)[~]$ nano fichier1 & (formation㉿lubuntu01)[~]$ nano fichier2 & (formation㉿lubuntu01)[~]$ jobs [1]- Stopped nano fichier1 [2]+ Stopped nano fichier2 Reprendre un programme en tâche de fond : ''fg'' (formation㉿lubuntu01)[~]$ fg 2 nano fichier2 \\ ==== Connaître le shell courant ==== readlink "/proc/$$/exe" \\ ==== Récupérer le PID d'un processus ==== ping localhost & echo "PID du processus courant : $$" echo "PID du processus lancé (ping localhost) : $!" sleep 3 kill $! exit 0 \\ ==== Kill (signaux principaux) ==== ^Signal^Commande^Description^ |9 SIGKILL|''kill -9 ''|Tuer un processus| |15 SIGTERM|''kill -15 ''|Arrêter un processus| |19 SIGSTOP|''kill -19 ''|Suspendre un processus (eq. Ctrl+z)| |18 SIGCONT|''kill -18 ''|Réactiver un processus suspendu| |2 SIGINT|''kill -2 ''|Interrompre un processus (eq. Ctrl+c)| \\ ==== Tuer tous les process lançant le même programme ==== for PID in `ps -ef | grep "ingres" | awk '{print $2}'` do kill -9 ${PID} done \\ ==== Lister les processus qui consomment le plus de CPU ==== ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu uniquement ceux > à 0 % : ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d' \\ ==== Lister les threads d'un processus ==== ps -C mysqld -L -o pid,tid,pcpu,state,cputime,args \\ ==== Tracer les appels système d'un processus ==== strace -p PID \\ ==== Tracer les appels système d'un processus qui fait des fork, et filtrer la sortie ==== strace -F -p PID 2>&1 |grep -v "FILTRE" \\ ==== Tracer l'utilisation des sockets d'un processus ==== strace -e trace=network -p PID