Skip to main content
1 of 2
cas
  • 84.4k
  • 9
  • 136
  • 205

ps now has output options for the different types of namespaces associated with processes: ipcns, mntns, netns, pidns, userns, and utsns. For this question, the relevant one is the PID namespace, or pidns.

so if you wanted to find out the PID namespace id for, e.g., pid 459:

# ps -h -o pidns -p 459
4026532661

and to list all processes in that namespace:

ps -o pidns,pid,cmd | awk '$1==4026532661'

or with pgrep, you can go directly from a PID to a list of all processes sharing that same PID namespace:

pgrep -a --ns 459

Unlike ps, pgrep can limit the output to a specific namespace (if you know the PID of one of the processes in it), but has very limited output formatting capabilities (PIDs only, or PIDs and their command lines)

cas
  • 84.4k
  • 9
  • 136
  • 205