0

Is the name of the thread group leader available in /proc? I am looking for the group_leader->comm field for a given task_struct.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
anglee
  • 99
  • 2
  • 12
  • The `/proc` directory seems to be structured like `/proc/$TGID/task/$PID/`, where `$TGID` is the thread group ID (the PID) and `$PID` is the thread ID (TID). (The differences in terminology between userspace and kernelspace are confusing!). Also the `/proc/$TGID/task/$PID/status` file will list "Tgid" (the thread group ID, i.e. the process PID, which I showed as $TGID above), "Ngid" (the Numa group ID), "Pid" (the thread ID, i.e. the TID, which I showed as $PID above), "Ppid" (the parent process ID), and other stuff. The name of the thread group leader will be shown in `/proc/$TGID/comm`. – Ian Abbott Oct 14 '19 at 17:32
  • `/proc/$TGID/comm` is name of the thread itself and not the name of the group_leader. This is how its showing up on my Centos7. Are you sure you're seeing the group_leader name? – anglee Oct 14 '19 at 20:51
  • 1
    Yes, you are correct. All PIDs including TIDs show up under `/proc/$PID`. The `/proc/$PID/status` file will list the threag group leader as "Tgid: $TGID" and then you you can read `/proc/$TGID/comm` to get the name of the thread group leader. – Ian Abbott Oct 15 '19 at 09:32
  • "show up" in procfs is misleading: a directory read will return only process-related entries (with a PID number). In contrast path traversal also resolves TIDs. – TheDiveO May 26 '22 at 17:57

0 Answers0