From 7b058c74368068c63d9bb5395344f467ec9e4ca4 Mon Sep 17 00:00:00 2001 From: Conor Branagan Date: Wed, 2 Aug 2017 13:49:55 -0400 Subject: [PATCH] Just look at filenames for linux NumFDs call. In NumFDs we don't care about the contents of the fields, just how many there are. --- process/process_linux.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/process/process_linux.go b/process/process_linux.go index c0d81c2..af44dfe 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -219,7 +219,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) { // NumFDs returns the number of File Descriptors used by the process. func (p *Process) NumFDs() (int32, error) { - numFds, _, err := p.fillFromfd() + numFds, _, err := p.fillFromfdList() return numFds, err } @@ -514,16 +514,25 @@ func (p *Process) fillFromLimits() ([]RlimitStat, error) { return limitStats, nil } -// Get num_fds from /proc/(pid)/fd -func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) { +// Get list of /proc/(pid)/fd files +func (p *Process) fillFromfdList() (string, []string, error) { pid := p.Pid statPath := common.HostProc(strconv.Itoa(int(pid)), "fd") d, err := os.Open(statPath) if err != nil { - return 0, nil, err + return statPath, []string{}, err } defer d.Close() fnames, err := d.Readdirnames(-1) + return statPath, fnames, err +} + +// Get num_fds from /proc/(pid)/fd +func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) { + statPath, fnames, err := p.fillFromfdList() + if err != nil { + return 0, nil, err + } numFDs := int32(len(fnames)) var openfiles []*OpenFilesStat