function::ns_pid - Linux


ns_pid is a versatile Linux tool used to retrieve the process ID (PID) of a container’s network namespace, offering insights into the network configurations and interconnections within containerized environments.


ns_pid [ -n namespace ]


-n, –namespace

Specify the network namespace’s name or ID. Default: current namespace.


Get PID of current network namespace:

$ ns_pid

Get PID of a specific namespace:

$ ns_pid -n my-namespace

Common Issues

  • Namespace not found: Ensure the provided namespace name or ID is valid and accessible.


Combining with netstat:

$ ns_pid -n my-namespace | xargs netstat -nap --namespace

Using in scripts:


ns_pid=$(ns_pid -n my-namespace)
echo "PID of my-namespace: $ns_pid"

Related Commands

  • ip netns: Manage network namespaces.
  • ping: Network troubleshooting tool.

Further Reading