fileutils_unix.go 441 B

12345678910111213141516171819202122
  1. // +build linux freebsd
  2. package fileutils
  3. import (
  4. "fmt"
  5. "io/ioutil"
  6. "os"
  7. "github.com/Sirupsen/logrus"
  8. )
  9. // GetTotalUsedFds Returns the number of used File Descriptors by
  10. // reading it via /proc filesystem.
  11. func GetTotalUsedFds() int {
  12. if fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil {
  13. logrus.Errorf("Error opening /proc/%d/fd: %s", os.Getpid(), err)
  14. } else {
  15. return len(fds)
  16. }
  17. return -1
  18. }