Parses the tgid field, which is the thread group id (aka user-space process id) on Linux. Returns error on other platforms.

pull/471/head
Nick Kirsch 7 years ago
parent 27389f01ec
commit 482ca3af6d

@ -30,6 +30,8 @@ type Process struct {
lastCPUTimes *cpu.TimesStat
lastCPUTime time.Time
tgid int32
}
type OpenFilesStat struct {

@ -41,6 +41,9 @@ func (p *Process) Ppid() (int32, error) {
func (p *Process) Name() (string, error) {
return "", common.ErrNotImplementedError
}
func (p *Process) Tgid() (int32, error) {
return 0, common.ErrNotImplementedError
}
func (p *Process) Exe() (string, error) {
return "", common.ErrNotImplementedError
}

@ -100,6 +100,16 @@ func (p *Process) Name() (string, error) {
return p.name, nil
}
// Tgid returns tgid, a Linux-synonym for user-space Pid
func (p *Process) Tgid() (int32, error) {
if p.tgid == 0 {
if err := p.fillFromStatus(); err != nil {
return 0, err
}
}
return p.tgid, nil
}
// Exe returns executable path of the process.
func (p *Process) Exe() (string, error) {
return p.fillFromExe()
@ -820,6 +830,12 @@ func (p *Process) fillFromStatus() error {
return err
}
p.parent = int32(pval)
case "Tgid":
pval, err := strconv.ParseInt(value, 10, 32)
if err != nil {
return err
}
p.tgid = int32(pval)
case "Uid":
p.uids = make([]int32, 0, 4)
for _, i := range strings.Split(value, "\t") {

Loading…
Cancel
Save