Per Enqueue Zero, Nsenter is a utility enters the namespaces of one or more other processes and then executes the specified program. In other words, we jump to the inner side of the namespace.
Search for the namespace, by searching for S+, and then using the PID to target the namespace, and run the local tools in the namespace. This is very helpful where the docker container does not contain the necessary tools by default.
[root@localhost ~]# ps aux | grep 'S+'
gdm 1203 0.0 0.0 6084 1064 tty1 S+ 2021 0:00 dbus-run-session -- gnome-session --autostart /usr/share/gdm/greeter/autostart
root 24439 0.0 0.0 4420 632 pts/0 S+ 2021 0:00 tail -f /database/config/db2inst1/sqllib/db2dump/DIAG0000/db2diag.log
root 922523 0.0 0.0 221568 776 pts/0 S+ 14:07 0:00 grep --color=auto S+
[root@localhost ~]# nsenter --target 24439 --mount --uts --net --pid ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 12100 2416 pts/0 Ss+ 2021 0:01 /bin/bash /var/db2_setup/lib/setup_db2_instance.sh
root 14738 0.0 0.0 111996 5688 ? Ss 2021 33:46 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root 14741 0.0 0.0 4420 632 pts/0 S+ 2021 0:00 tail -f /database/config/db2inst1/sqllib/db2dump/DIAG0000/db2diag.log
root 14742 0.0 0.0 95724 12332 ? S 2021 5:59 /opt/ibm/db2/V11.5/bin/db2fmcd
root 14743 0.0 0.0 112952 5696 ? S 2021 0:00 /usr/sbin/sshd -D
root 65263 0.0 0.0 1313568 8708 ? Sl 2021 0:06 db2wdog 0 [db2inst1]
db2inst1 65265 0.1 0.1 3716884 30216 ? Sl 2021 88:11 db2sysc 0
root 65271 0.0 0.0 1316348 3548 ? S 2021 0:00 db2ckpwd 0
root 65272 0.0 0.0 1316348 3548 ? S 2021 0:00 db2ckpwd 0
root 65273 0.0 0.0 1316348 3544 ? S 2021 0:00 db2ckpwd 0
db2inst1 65275 0.0 0.0 723620 7448 ? S 2021 0:00 db2vend (PD Vendor Process - 1) 0
db2inst1 65283 0.0 0.1 961132 23452 ? Sl 2021 16:42 db2acd 0 ,0,0,0,1,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000
db2fenc1 66416 0.0 0.1 650952 20416 ? Sl 2021 0:01 db2fmp ( ,1,0,0,0,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000
db2fenc1 70651 0.0 0.1 424932 19852 ? Sl 2021 0:00 db2fmp ( ,0,0,0,0,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000
db2fenc1 2274960 0.0 0.1 424932 19872 ? Sl 2021 0:00 db2fmp ( ,0,0,0,0,0,0,00000000,0,0,0000000000000000,0000000000000000,00000000,00000
root 4113980 0.0 0.0 11704 2660 ? S 19:05 0:00 bash -c /var/db2_setup/lib/backup_cfg.sh >> /tmp/backup_cfg.out 2>&1
root 4113981 0.0 0.0 11704 2816 ? S 19:05 0:00 /bin/bash /var/db2_setup/lib/backup_cfg.sh
root 4114110 0.0 0.0 4380 736 ? S 19:05 0:00 sleep 2m
root 4114269 0.1 0.0 12100 3072 ? S 19:07 0:00 /bin/bash /var/db2_setup/lib/fix_etc_host.sh
root 4114285 0.0 0.0 4380 716 ? S 19:07 0:00 sleep 10
root 4114290 0.0 0.0 53348 3856 pts/0 R+ 19:07 0:00 ps aux
[root@localhost ~]#
Leave a Reply