Merge pull request #1116 from shirou/feature/port_to_v2_from_1112

[v2][process][linux] port 1112 to v2.
pull/1117/head
shirou 4 years ago committed by GitHub
commit ab783600d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -82,7 +82,7 @@ func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
if p.name == "" {
if err := p.fillFromStatusWithContext(ctx); err != nil {
if err := p.fillNameWithContext(ctx); err != nil {
return "", err
}
}
@ -517,6 +517,28 @@ func limitToInt(val string) (int32, error) {
}
}
// Get name from /proc/(pid)/comm or /proc/(pid)/status
func (p *Process) fillNameWithContext(ctx context.Context) error {
err := p.fillFromCommWithContext(ctx)
if err == nil && p.name != "" && len(p.name) < 15 {
return nil
}
return p.fillFromStatusWithContext(ctx)
}
// Get name from /proc/(pid)/comm
func (p *Process) fillFromCommWithContext(ctx context.Context) error {
pid := p.Pid
statPath := common.HostProc(strconv.Itoa(int(pid)), "comm")
contents, err := ioutil.ReadFile(statPath)
if err != nil {
return err
}
p.name = strings.TrimSuffix(string(contents), "\n")
return nil
}
// Get num_fds from /proc/(pid)/limits
func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat, error) {
pid := p.Pid

Loading…
Cancel
Save