Add -b option to lsof to avoid kernel blocks.

This commit is contained in:
Michael Baird 2017-06-13 16:14:45 -05:00
parent 1e793a1c52
commit cd532e08cb
2 changed files with 8 additions and 3 deletions

View file

@ -157,3 +157,5 @@ We currently track the following events
<strong id="garbage_collection">Garbage Collection:</strong> Event count when Garbage Collection occurs.
<strong id="goroutines">Goroutines:</strong> Number of running Goroutines.
<strong id="openfiles">OpenFiles:</strong> Number of open file handles associated with running Pilosa process ID.

View file

@ -513,12 +513,15 @@ func CountOpenFiles() int {
case "unix":
fallthrough
case "freebsd":
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output()
// -b option avoid kernel blocks
pid := os.Getpid()
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -b -p %v", pid)).Output()
if err != nil {
log.Fatal(err)
}
lines := strings.Split(string(out), "\n")
count = len(lines) - 1
// only count lines with our pid, avoiding warning messages from -b
lines := strings.Split(string(out), strconv.Itoa(pid))
count = len(lines)
case "windows":
// TODO: count open file handles on windows
default: