0

While examining Linux Kernel, to get the process ID they use:

pid_t pid = current->pid;

But in some places I saw:

pid_t pid = task_tgid_vnr(current);

I wonder the rationale behind it and where should I use the one instead of the other?

(Detailed explanations will also be welcomed)

red0ct
  • 4,840
  • 3
  • 17
  • 44
Fredrick Gauss
  • 5,126
  • 1
  • 28
  • 44
  • `pid` is proccess pid, `tgid` is thread thread group id. These are different things. What you want `tgid` access `current->tgid`, when you want `pid` use `current->pid`. – KamilCuk Jan 10 '19 at 07:46
  • @KamilCuk, why dont we use `current->tgid` instead of `task_tgid_vnr` ? – Fredrick Gauss Jan 10 '19 at 08:09
  • @FredrickGauss search for duplicates before asking a question next time. :) – gsamaras Jan 10 '19 at 08:34
  • @gsamaras, I already searched but could not find a decent explanation about `task_tgid_vnr`. – Fredrick Gauss Jan 10 '19 at 08:36
  • 1
    `task_tgid_vnr` fetches the `tgid` from a the pid namespace, while `current->tgid` is from init namespace. You check man pid_namespace and [kernel soruce](https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h#L1233). – KamilCuk Jan 10 '19 at 08:41

0 Answers0