File: fileutils_darwin.go

package info (click to toggle)
docker.io 27.5.1%2Bdfsg4-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 67,452 kB
  • sloc: sh: 5,847; makefile: 1,146; ansic: 664; python: 162; asm: 133
file content (27 lines) | stat: -rw-r--r-- 856 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package fileutils // import "github.com/docker/docker/pkg/fileutils"

import (
	"bytes"
	"os"
	"os/exec"
	"strconv"
)

// GetTotalUsedFds returns the number of used File Descriptors by executing
// "lsof -lnP -Ff -p PID".
//
// It uses the "-F" option to only print file-descriptors (f), and the "-l",
// "-n", and "-P" options to omit looking up user-names, host-names, and port-
// names. See [LSOF(8)].
//
// Deprecated: this function is only used internally, and will be removed in the next release.
//
// [LSOF(8)]: https://opensource.apple.com/source/lsof/lsof-49/lsof/lsof.man.auto.html
func GetTotalUsedFds() int {
	output, err := exec.Command("lsof", "-lnP", "-Ff", "-p", strconv.Itoa(os.Getpid())).CombinedOutput()
	if err != nil {
		return -1
	}

	return bytes.Count(output, []byte("\nf")) // Count number of file descriptor fields in output.
}