I am checking the namespaces associated with a shell process as follows:
# ll /proc/$$/ns
total 0
dr-x--x--x 2 root root 0 May 2 15:10 ./
dr-xr-xr-x 9 root root 0 May 1 18:39 ../
lrwxrwxrwx 1 root root 0 May 2 15:11 cgroup -> cgroup:[4026531835]
lrwxrwxrwx 1 root root 0 May 2 15:11 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 root root 0 May 2 15:11 mnt -> mnt:[4026531840]
lrwxrwxrwx 1 root root 0 May 2 15:11 net -> net:[4026531957]
lrwxrwxrwx 1 root root 0 May 2 15:11 pid -> pid:[4026531836]
lrwxrwxrwx 1 root root 0 May 2 15:11 user -> user:[4026531837]
lrwxrwxrwx 1 root root 0 May 2 15:11 uts -> uts:[4026531838]
I understand that the entries indicate which namespaces a process is associated with. I want to ask where the numbers, identifying each namespace, come from?
For example, the output above indicates that the process mount namespace is mnt:[4026531840]
. I checked the mount namespace structure:
8 struct mnt_namespace {
9 atomic_t count;
10 struct ns_common ns;
11 struct mount * root;
12 struct list_head list;
13 struct user_namespace *user_ns;
14 struct ucounts *ucounts;
15 u64 seq; /* Sequence number to prevent loops */
16 wait_queue_head_t poll;
17 u64 event;
18 unsigned int mounts; /* # of mounts in the namespace */
19 unsigned int pending_mounts;
20 } __randomize_layout;
I don't see a field that serves as an identifier to be used in /proc/PID/ns/
entries. So how are these identifiers generated?
/proc/$$/ns
correspond to .. namespace of the main thread of the process ? Because for each thread there would be an entry in/proc/$$/task/ID/ns
. – Jake May 02 '19 at 23:33/proc/$$/ns
corresponds to the namespaces of the main thread (the thread whose TID = PID) – May 03 '19 at 00:10