Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created October 5, 2015 14:11
Show Gist options
  • Save orcaman/a626f9f4af2a491dd9d1 to your computer and use it in GitHub Desktop.
Save orcaman/a626f9f4af2a491dd9d1 to your computer and use it in GitHub Desktop.
Golang: count open files
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