Created
October 5, 2015 14:11
-
-
Save orcaman/a626f9f4af2a491dd9d1 to your computer and use it in GitHub Desktop.
Golang: count open files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func countOpenFiles() int64 { | |
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output() | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
lines := strings.Split(string(out), "\n") | |
return int64(len(lines) - 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment