github.com/moby/docker@v26.1.3+incompatible/pkg/fileutils/fileutils_darwin.go (about) 1 package fileutils // import "github.com/docker/docker/pkg/fileutils" 2 3 import ( 4 "bytes" 5 "os" 6 "os/exec" 7 "strconv" 8 ) 9 10 // GetTotalUsedFds returns the number of used File Descriptors by executing 11 // "lsof -lnP -Ff -p PID". 12 // 13 // It uses the "-F" option to only print file-descriptors (f), and the "-l", 14 // "-n", and "-P" options to omit looking up user-names, host-names, and port- 15 // names. See [LSOF(8)]. 16 // 17 // [LSOF(8)]: https://opensource.apple.com/source/lsof/lsof-49/lsof/lsof.man.auto.html 18 func GetTotalUsedFds() int { 19 output, err := exec.Command("lsof", "-lnP", "-Ff", "-p", strconv.Itoa(os.Getpid())).CombinedOutput() 20 if err != nil { 21 return -1 22 } 23 24 return bytes.Count(output, []byte("\nf")) // Count number of file descriptor fields in output. 25 }