Container Basics On Linux (Namespaces/Cgroups)
Stop container processes from lying about their own PID
đź§© The Challenge
You ever run ps inside a container and see a process ID of 1, but when you look from the host, that same process is actually something like 45021? I’ve spent way too much time hunting down logs because I mixed up the host PID with the namespace-isolated PID.
đź’ˇ The Fix
Use the nsenter utility to jump into the container’s PID namespace so you can see the world exactly how the container sees it. It saves you from having to guess which process maps to which container.
nsenter -t <pid_on_host> -p ps aux
⚙️ Why It Works
By joining the PID namespace of the target process, you effectively move your shell into that process’s sandbox, making the local process table visible as if you were running inside the container itself.
🚀 Pro-Tip: Add the -m flag if you also need to see the filesystem as it appears to that container.
Linux Tips & Tricks | © ngelinux.com | 8/19/2026
