Tgid() function gives no useful information
Describe the bug I will discuss this bug from the Linux perspective since Tgid() function is not implemented for other platforms. We have a Tgid() function which parses the /proc/[pid]/status file for a PID and fills TGID from it. This TGID is PID in the userspace or TGID in the kernelspace. On the other hand, the Pid field is filled by the Pids() function which looks at the directories in the /proc directory. These subdirectories of the /proc directory are also PIDs in the userspace or TGIDs in the kernelspace. So, they both provide the same information. We can confirm this behavior by printing both the Pid field and the result of the Tgid() function. They are always the same.
The problem with this API is that existence of the Tgid() function (which returns correct information "tgid") can have a wrong implication that the Pid field is actually TID. Either Tgid() function should be removed or another function should be added to return TID (pid from /proc/[pid]/status file).
To Reproduce
package main
import (
"log"
"github.com/shirou/gopsutil/v3/process"
)
func main() {
processes, _ := process.Processes()
for _, proc := range processes {
tgid, err := proc.Tgid()
if err != nil {
continue
}
pid := proc.Pid
if tgid != pid {
log.Panicf("TGID (%d) != PID (%d)\n", tgid, pid)
}
}
log.Printf("all tgids are equal to pids")
}
Environment (please complete the following information):
- [ ] Linux:
/etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
uname -a
Linux saboor 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
I'm OK with removing this API, it's only defined on Linux anyway when gopsutil wants to provide the same information on supported platforms.