fileutils_linux.go 435 B

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