add fileutils_darwin.go in pkg/fileutils to support darwin platform
Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
parent
f718d6b8c6
commit
0df28b9294
1 changed files with 27 additions and 0 deletions
27
fileutils/fileutils_darwin.go
Normal file
27
fileutils/fileutils_darwin.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue