ps lies until you remount /proc¶
Claim — a new PID namespace renumbers processes, but ps still shows the host's until you give the namespace its own /proc. The PID namespace and the mount namespace are separate things, and this is the first place that separation bites.
Topology — bare, still up from the UTS namespace, still as root.
Do
unshare --pid --fork bash— without--mount-proc. Runps aux. Read the PIDs.- Now
echo $$. Compare that number with whatpsreports for the same shell. exit, and redo it asunshare --pid --fork --mount-proc bash. Runps auxagain.- Inside,
echo $$andls /proc | head. - From a second session on the host, find the same shell process and read its PID. One process, two numbers, both correct.
Observe
echo $$ # inside: 1
ps aux | wc -l # before --mount-proc: the host's count
# after: two or three lines
ls -l /proc/self/ns/pid /proc/self/ns/mnt # both differ from the host's
Expect — without --mount-proc, $$ says 1 while ps lists every process on the box. ps is not lying about the kernel; it is reading /proc, which is still the host's /proc mount, which reports host PIDs. --mount-proc unshares the mount namespace as well and mounts a fresh procfs, which the kernel renders from the reader's PID namespace. After that, ps shows two processes and $$ is 1.
Write down — one sentence on why /proc is a mount and not a namespace, and what that implies for any tool that reports on processes. Add the PID row to your seven-namespaces table.
Teardown — exit. Nothing persists: the namespace dies with its last process, and the procfs mount died with the mount namespace. Guest stays up.