github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/pkg/fileutils/fileutils_darwin.go (about) 1 package fileutils // import "github.com/docker/docker/pkg/fileutils" 2 3 import ( 4 "os" 5 "os/exec" 6 "strconv" 7 "strings" 8 ) 9 10 // GetTotalUsedFds returns the number of used File Descriptors by 11 // executing `lsof -p PID` 12 func GetTotalUsedFds() int { 13 pid := os.Getpid() 14 15 cmd := exec.Command("lsof", "-p", strconv.Itoa(pid)) 16 17 output, err := cmd.CombinedOutput() 18 if err != nil { 19 return -1 20 } 21 22 outputStr := strings.TrimSpace(string(output)) 23 24 fds := strings.Split(outputStr, "\n") 25 26 return len(fds) - 1 27 }