github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/pkg/fileutils/fileutils_darwin.go (about)

     1  package 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  }