2
votes

Im trying to understand better how the kernel implement pid namespace . One of the basic structure that is being used is struct pid :

struct pid { 
      atomic_t count;
      unsigned int level;
      /* lists of tasks that use this pid */
      struct hlist_head tasks[PIDTYPE_MAX];
      struct rcu_head rcu;
      struct upid numbers[1]; }

Now from what I understand numbers array keeps track of the process different pids in different pid namespaces.

What I dont understand is the purpose of tasks member. It says here: (LWN) :

.." This structure contains the ID value, the list of tasks having this ID.."

So I understand from this that the same pid is shared between couple of proccess/tasks . Now, different proccess/threads can share same tpid/gpid but not the same pid! So how come there are list of tasks having the same PID? What am I missing?

Thanks

1
There is always only a single element pointed by pid.tasks[PIDTYPE_PID]. Tasks do not share the PID but they can share PGID and SID. They are all on the same array for uniformity and code sharing.Karim Manaouil

1 Answers

1
votes

A struct pid is the kernel's internal notion of a process identifier. It can identify a process, a thread, as much as a session or process group. That's why there is a list of task.

It's explained in the kernel code that it's a compromise between :

  • store only pid_t which don't garantee that the process identified is the one you want because pids are reused in a cycle way
  • store pointers for each thread of processes, which results in a too big table