fileutils_unix.go 515 B

12345678910111213141516171819202122
  1. //go:build linux || freebsd
  2. package fileutils // import "github.com/docker/docker/pkg/fileutils"
  3. import (
  4. "context"
  5. "fmt"
  6. "os"
  7. "github.com/containerd/containerd/log"
  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 := os.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil {
  13. log.G(context.TODO()).Errorf("Error opening /proc/%d/fd: %s", os.Getpid(), err)
  14. } else {
  15. return len(fds)
  16. }
  17. return -1
  18. }