Table des matières
3 billet(s) pour janvier 2026
| Notes rsh rcp | 2026/01/21 18:08 | Jean-Baptiste |
| Git - Duplication d'un dépôt | 2026/01/19 10:22 | Jean-Baptiste |
| Exemple simple de conf Nagios | 2026/01/14 10:07 | Jean-Baptiste |
Programmation
Voir :
Lisp / Programmation Fonctionnelle :
La fin de la programmation ? https://www.lemonde.fr/blog/internetactu/2016/05/21/demain-la-fin-du-code/ (début de l'article intéressant)
Les Processus sous Linux
Voir aussi :
/proc/sys/kernel/ns_last_pid
Tuer tous les processus d'un utilisateur
pkill -u plop
Appels système au noyaux et signaux
strace -p $PID strace -f -e trace=file $CHEMIN_EXE 2>&1 | grep '/home/'
La table des processus
ps -ef |grep $PID # ps -Aww -o pid,ppid,user,start,state,pri,pcpu,time:12,pmem,rsz:10,vsz:10,cmd
2em colone ⇒ PID 3em colone ⇒ PPID
Qui a lancé ce processus ? PPID ? Service ?
journalctl _PID=2636 -o json-pretty
Que fait TTY1 ?
peekfd -cn8 $(ps -t tty1 |grep -v login |sort -nr |head -1 |awk '{print $1}')
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://www.cyberciti.biz/faq/linux-hide-processes-from-other-users/ http://www.linux-dev.org/2012/09/hide-process-information-for-other-users/ http://tuxdiary.com/2014/08/23/hidepid/
Modifier la ligne */proc* dans /etc/fstab. Si aucune ligne ne correspond, ajouter la
- fstab
proc /proc proc defaults,hidepid=2,gid=4 0 0
Pour appliquer la modif sans redemarrer :
mount -o remount /proc/
Audit process
Voir execsnoop et autres : https://access.redhat.com/documentation/fr-fr/red_hat_enterprise_linux/9/html/managing_monitoring_and_updating_the_kernel/using-selected-bcc-tools-for-performance-analyses_analyzing-system-performance-with-bpf-compiler_collection paquet bcc-tools
Arrière plan
Using the Job Control of bash to send the process into the background:
- 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://stackoverflow.com/questions/625409/how-do-i-put-an-already-running-process-under-nohup
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é rsync -azS --partial /data/1/ $FIC root@192.168.205.2:/data/files/1/ [2]- En cours d'exécution rsync -azS --partial /data/2/ $FIC root@192.168.205.2:/data/files/2/ & jobs %% jobs %1
Stopper le job1
kill -19 %1
Lancer le job2 une fois le job1 terminé
wait %2; kill -18 %1
http://linuxfr.org/users/srb/journaux/waitend-executer-une-commande-apres-une-autre-deja-lancee
sleep $(( 60 * 3 )) ; echo "Les œufs sont prêt"
sleep $(( 60 * 3 )) && echo "Les œufs sont prêt"
sleep $(( 60 * 3 )) & wait $! echo "Les œufs sont prêt"
sleep $(( 60 * 3 ))
[Ctrl] + [Z]
fg && echo "Les œufs sont prêt"
Autres
Voir atop, htop Voir cgroup
kthreadd
Voir https://www.it-connect.fr/les-processus-sous-linux
# ps -ef |head -40 UID PID PPID C STIME TTY TIME CMD root 1 0 0 Mar15 ? 00:02:12 /sbin/init root 2 0 0 Mar15 ? 00:00:00 [kthreadd] root 3 2 0 Mar15 ? 19:02:47 [migration/0] root 4 2 0 Mar15 ? 00:07:26 [ksoftirqd/0] root 5 2 0 Mar15 ? 00:00:00 [stopper/0] root 6 2 0 Mar15 ? 00:07:33 [watchdog/0] root 7 2 0 Mar15 ? 18:46:13 [migration/1] root 8 2 0 Mar15 ? 00:00:00 [stopper/1] root 9 2 0 Mar15 ? 00:07:05 [ksoftirqd/1] root 10 2 0 Mar15 ? 00:06:16 [watchdog/1] root 11 2 0 Mar15 ? 18:55:58 [migration/2] root 12 2 0 Mar15 ? 00:00:00 [stopper/2] root 13 2 0 Mar15 ? 00:06:45 [ksoftirqd/2] root 14 2 0 Mar15 ? 00:06:04 [watchdog/2] root 15 2 0 Mar15 ? 19:15:39 [migration/3] root 16 2 0 Mar15 ? 00:00:00 [stopper/3] root 17 2 0 Mar15 ? 00:06:43 [ksoftirqd/3] root 18 2 0 Mar15 ? 00:05:41 [watchdog/3] root 19 2 0 Mar15 ? 18:54:50 [migration/4] root 20 2 0 Mar15 ? 00:00:00 [stopper/4] root 21 2 0 Mar15 ? 00:06:48 [ksoftirqd/4] root 22 2 0 Mar15 ? 00:06:09 [watchdog/4] root 23 2 0 Mar15 ? 18:51:16 [migration/5] root 24 2 0 Mar15 ? 00:00:00 [stopper/5] root 25 2 0 Mar15 ? 00:06:06 [ksoftirqd/5] root 26 2 0 Mar15 ? 00:05:27 [watchdog/5] root 27 2 0 Mar15 ? 18:59:33 [migration/6] root 28 2 0 Mar15 ? 00:00:00 [stopper/6] root 29 2 0 Mar15 ? 00:06:27 [ksoftirqd/6] root 30 2 0 Mar15 ? 00:05:13 [watchdog/6] root 31 2 0 Mar15 ? 19:15:16 [migration/7] root 32 2 0 Mar15 ? 00:00:00 [stopper/7] root 33 2 0 Mar15 ? 00:06:16 [ksoftirqd/7] root 34 2 0 Mar15 ? 00:06:33 [watchdog/7]
Nous pouvons constater immédiatement quatre choses :
- Les processus '[migration/n]', contrairement aux processus classiques, on leurs noms entre des crochets []
- Le process père est [kthreadd] (PPID 2)
- Nous avons 8 processus : migration/0..migration/7. Soit un par core.
- Ces processus sont démarrés depuis le démarrage du système d'exploitation soit le 15 mars.
$ LANG=C man ps "Sometimes the process args will be unavailable; when this happens, ps will instead print the executable name in brackets"
Les zombies
Tuer les zombies !
Source : https://www.linuxjournal.com/content/how-kill-zombie-processes-linux
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/execution but for some reason, its parent process didn’t clean it up properly after the execution.
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:
ps aux | egrep "Z|defunct"
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):
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:
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:
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, if few lying zombie processes are not consuming much CPU/Memory, it’s better to kill the parent process or reboot the system in the next scheduled system maintenance.
Strace
Voir : https://aurelien-riv.github.io/php/2019/12/28/what-process-waiting-for.html
Exemple :
strace -e trace=network -f iceweasel http://acme.com 2>&1 |grep '8.8.8.8' strace -ttfv -s128 -o /var/tmp/ping-$(hostname)-$(date +%Y.%m.%d-%H.%M).out ping -c1 acme.com strace -f -p $(pidof mariadbd) --trace=sendto,recvfrom -s 2048 2>&1 | grep -i update vimdiff <(cat plop.log |sed -e 's/^\[pid [0-9]\+\] //') <(cat plop.err |sed -e 's/^\[pid [0-9]\+\] //')
Process audit quand strace n'est pas là
Voir :
- /proc/[PID]/
- procmap
lsof -p 33279 ps -efL |grep plop |wc -l ss -tnp |grep plop tcpdump -A -s0 host 192.168.100.5 and port 21 dmesg pmap 33279 strace -r -o trace.log sudo echo hi
Pour voir les E/S sur les FD
peekfd -n -8 -d -c 32167 0 1 2
Notes strace
A debugging utility for Linux, monitors system calls used by a program and all received signals
Voir aussi :
- eBPF – Linux kernel tracing backend providing a set of features similar to DTrace[28] since kernel version 4.9
- ftrace – a tracing framework for the Linux kernel, capable of tracing scheduling events, interrupts, memory-mapped I/O, CPU power state transitions, etc.
- ltrace – a Linux debugging utility, displays the calls a userland application makes to shared libraries
- SystemTap – a scripting language and utility used for instrumenting Linux installations
-s strsize Specifies the maximum string size to print (the default is 32). Note that filenames are not considered strings and are always printed in full.
Activer / interdire strace
kernel.yama.ptrace_scope = 0: all processes can be debugged, as long as they have same uid. This is the classical way of how ptracing worked.
kernel.yama.ptrace_scope = 1: only a parent process can be debugged.
kernel.yama.ptrace_scope = 2: Only admin can use ptrace, as it required CAP_SYS_PTRACE capability.
kernel.yama.ptrace_scope = 3: No processes may be traced with ptrace. Once set, a reboot is needed to enable ptracing again.
# LANG=C strace -p 1171 strace: attach: ptrace(PTRACE_ATTACH, 1171): Operation not permitted # echo 0 > /proc/sys/kernel/yama/ptrace_scope # LANG=C strace -p 1171
strace -T -tt -f -v -q -s 4096 -o /tmp/nonworking_cp-strace.out <cp command> &> /tmp/nonworking_cp.out strace -fvttTyyx -s 1024 -o /tmp/strace.out <command> &> /tmp/df.out
Autre
Auditer les signaux / les kills
Comparaison entre différents environnements
Voir procenv
Power saver - power management - ACPI
Voir :
Diag
ps -ef lsmof
SystemD
/etc/systemd/logind.conf
HandleLidSwitch=ignore
systemctl restart systemd-logind busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager HandleLidSwitch busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager HandleLidSwitchDocked
You can use this to temporarily disable lid-switch events:
systemd-inhibit --what=handle-lid-switch sleep 1d
systemctl suspend
systemctl hibernate
systemctl hybrid-sleep
Disable
sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Pour les portables /etc/systemd/logind.conf
[Login] HandleLidSwitch=ignore HandleLidSwitchDocked=ignore
Notes
apt-get install pm-utils laptop-mode-tools
Console
/etc/console-tools/config
BLANK_TIME=0 POWERDOWN_TIME=0
source : https://wiki.deimos.fr/D%C3%A9sactiver_la_mise_en_veille_de_l%27%C3%A9cran_sur_Debian.html
Battery
cat /sys/class/power_supply/BAT0/charge_full cat /sys/class/power_supply/BAT0/charge_full_design lspower
sudo apt install powertop sudo powertop --calibrate apt-get install tlp sudo vim /etc/default/tlp sudo tlp start
Voir https://linrunner.de/en/tlp/docs/tlp-configuration.html
Source : https://www.howtogeek.com/55185/how-to-maximize-the-battery-life-on-your-linux-laptop/
ACPI
apt-get install acpid
acpi_listen
cat /proc/acpi/wakeup Device S-state Status Sysfs node
acpi/interrupts
AE_NOT_FOUND infinitely on startup
Source : https://unix.stackexchange.com/questions/348806/acpi-exception-ae-not-found-infinitely-on-startup
If using sysdemd with rc.local disabled:
systemctl enable rc-local.service
Edit
sudo systemctl edit --full rc-local
Add to rc.local
echo "disable" > /sys/firmware/acpi/interrupts/gpe6F
C-STATE
https://www.golinuxhub.com/2018/06/what-cpu-c-states-check-cpu-core-linux.html
cat /proc/acpi/processor/CPU0/power
Port USB
Le port USB se met en économie d’énergie. Par exemple la souris ne fonctionne plus après la sortie de la veille.
Voir https://logfile.ch/linux/2017/06/15/disable-usb-autosuspend-linux/
cat /sys/bus/usb/devices/<your device>/power/control echo on > /sys/bus/usb/devices/<your device>/power/control
Autres
Voir https://www.geeks3d.com/hacklab/20160108/how-to-disable-the-blank-screen-on-raspberry-pi-raspbian/
sudo apt-get install x11-xserver-utils
~/.config/lxsession/LXDE/autostart
@xset s off @xset -dpms @xset s noblank
/etc/xdg/lxsession/LXDE/autostart !?
Ou
/etc/lightdm/lightdm.conf
[SeatDefaults] xserver-command=X -s 0 -dpms
Exécution à l'entrée en veille / Exécution à la sortie de la mise en veille
Exemple
/lib/systemd/system-sleep/atop-pm
#!/bin/bash PATH=/sbin:/usr/sbin:/bin:/usr/bin case "$1" in pre) systemctl stop atop exit 0 ;; post) systemctl start atop exit 0 ;; *) exit 1 ;; esac
Postgres - se connecter a une socket
ps -ef |grep postgres
Trouver le PID du process Postgres père
Exemple : 2962
# ls -l /proc/2962/fd/ |grep socket lrwx------. 1 postgres postgres 64 Aug 8 06:55 3 -> socket:[25104] lrwx------. 1 postgres postgres 64 Aug 8 06:55 4 -> socket:[25106] lrwx------. 1 postgres postgres 64 Aug 8 06:55 8 -> socket:[25118]
# #lsof -i -a -p 2962 # #find / -user postgres -type s 2>/dev/null # #netstat -lx |egrep "25104|25106|25118" # ss -xl |egrep "25104|25106|25118" u_str LISTEN 0 2048 /tmp/.s.PGSQL.5455 25106 * 0
su - postgres
$ psql -h /tmp/.s.PGSQL.5455
psql: error: could not connect to server: Not a directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5455/.s.PGSQL.5432"?
$ psql -h /tmp
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Solution
psql -h /tmp -p 5455
