fds.go 355 B

12345678910111213141516171819
  1. // +build !windows,!darwin
  2. package osutils
  3. import (
  4. "io/ioutil"
  5. "path/filepath"
  6. "strconv"
  7. )
  8. // GetOpenFds returns the number of open fds for the process provided by pid
  9. func GetOpenFds(pid int) (int, error) {
  10. dirs, err := ioutil.ReadDir(filepath.Join("/proc", strconv.Itoa(pid), "fd"))
  11. if err != nil {
  12. return -1, err
  13. }
  14. return len(dirs), nil
  15. }