/proc/[pid]/ns/net contains a link to the inode representing the network namespace of the process with PID [pid]. Is there something similar for threads?

My use case is a multi-threaded application, where there's one main thread and a group of worker threads. The generic worker W creates a new network namespace N with a call to unshare() (which makes W enter N), pushes one end of a veth pair in N and leaves it (it uses an fd pointing to the root namespace to go back to such namespace). Since no processes are in N after W goes back to the root namespace, N is destroyed when that happens, and I do not want that.

The solution I thought about is to mount a link to N somewhere in the filesystem. This is what iproute2 netns does: mounting a link to /proc/[pid]/ns/net. The problem, in my case, is that /proc/[pid]/ns/net keeps referencing the root namespace, only W changes namespace, hence I cannot use it and I need a file/something else which points to the namespace of a thread. Is there such a thing in Linux?


1 Answer 1


There is a file that associates a thread to its network namespace:


where TID is the thread ID. This solved my issue.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .