2016-01-21 05:57:02 +00:00
|
|
|
// +build !windows,!darwin
|
|
|
|
|
2016-02-16 23:10:18 +00:00
|
|
|
package osutils
|
2015-12-09 22:40:55 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetOpenFds returns the number of open fds for the process provided by pid
|
|
|
|
func GetOpenFds(pid int) (int, error) {
|
|
|
|
dirs, err := ioutil.ReadDir(filepath.Join("/proc", strconv.Itoa(pid), "fd"))
|
|
|
|
if err != nil {
|
|
|
|
return -1, err
|
|
|
|
}
|
|
|
|
return len(dirs), nil
|
|
|
|
}
|