Vaibhav Khanduja
Vaibhav Khanduja

Reputation: 141

Access /proc/<pid>/ns/pid -> inode number

I am trying to get access to inode number of pid namespace which can be seen using ls -Li /proc/<pid>/ns/mnt or /proc/<pid>/ns/pid.

I am a newbie to kernel code, want to know in kernel, from current task structure how can I get this value? Some code would really help.

Upvotes: 0

Views: 1100

Answers (1)

Vaibhav Khanduja
Vaibhav Khanduja

Reputation: 141

The current task structure can be looked into for pid_namespace struct, which has the this field proc_inum:

task_active_pid_ns(current)->proc_inum;

EDIT: From kernel version 3.19 onwards, the pid_namespace struct has received an update that includes the addition of the ns_common struct that is defined in the header file: /include/linux/ns_common.h.

The ns_common struct is defined as follows:

struct ns_common {
    atomic_long_t stashed;
    const struct proc_ns_operations *ops;
    unsigned int inum;
};

The new pid_namespace struct is defined to include ns_common struct and does not contain the proc_inum integer. Instead, the inode number can be accessed using the ns_common struct.

So, the inode number can be obtained (from kernel v3.19 onwards) with the following line: task_active_pid_ns(current)->ns_common->inum

Source: https://elixir.bootlin.com/linux/v3.19/source/include/linux/pid_namespace.h

Upvotes: 2

Related Questions