瀏覽代碼

add fileutils_darwin.go in pkg/fileutils to support darwin platform

Signed-off-by: allencloud <allen.sun@daocloud.io>
allencloud 9 年之前
父節點
當前提交
d2dd1a1f7d
共有 1 個文件被更改,包括 27 次插入0 次删除
  1. 27 0
      pkg/fileutils/fileutils_darwin.go

+ 27 - 0
pkg/fileutils/fileutils_darwin.go

@@ -0,0 +1,27 @@
+package fileutils
+
+import (
+	"os"
+	"os/exec"
+	"strconv"
+	"strings"
+)
+
+// GetTotalUsedFds returns the number of used File Descriptors by
+// executing `lsof -p PID`
+func GetTotalUsedFds() int {
+	pid := os.Getpid()
+
+	cmd := exec.Command("lsof", "-p", strconv.Itoa(pid))
+
+	output, err := cmd.CombinedOutput()
+	if err != nil {
+		return -1
+	}
+
+	outputStr := strings.TrimSpace(string(output))
+
+	fds := strings.Split(outputStr, "\n")
+
+	return len(fds) - 1
+}