Merge pull request #471 from nkirsch/tgid_support

Add support for parsing the tgid (thread group id) field.
This commit is contained in:
shirou 2018-01-09 11:09:00 +09:00 committed by GitHub
commit 49e4d328f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 0 deletions

View File

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

View File

@ -83,6 +83,9 @@ func (p *Process) Name() (string, error) {
return common.IntToString(k.Proc.P_comm[:]), nil
}
func (p *Process) Tgid() (int32, error) {
return 0, common.ErrNotImplementedError
}
func (p *Process) Exe() (string, error) {
lsof_bin, err := exec.LookPath("lsof")
if err != nil {

View File

@ -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
}

View File

@ -50,6 +50,9 @@ func (p *Process) Name() (string, error) {
return common.IntToString(k.Comm[:]), nil
}
func (p *Process) Tgid() (int32, error) {
return 0, common.ErrNotImplementedError
}
func (p *Process) Exe() (string, error) {
return "", common.ErrNotImplementedError
}

View File

@ -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") {

View File

@ -53,6 +53,9 @@ func (p *Process) Name() (string, error) {
return common.IntToString(k.Comm[:]), nil
}
func (p *Process) Tgid() (int32, error) {
return 0, common.ErrNotImplementedError
}
func (p *Process) Exe() (string, error) {
return "", common.ErrNotImplementedError
}

View File

@ -154,6 +154,10 @@ func (p *Process) Name() (string, error) {
return name, nil
}
func (p *Process) Tgid() (int32, error) {
return 0, common.ErrNotImplementedError
}
func (p *Process) Exe() (string, error) {
dst, err := GetWin32Proc(p.Pid)
if err != nil {