code: func countOpenFiles() (int, error) {
  	switch runtime.GOOS {
  	case "darwin", "linux", "unix", "freebsd":
  		// -b option avoid kernel blocks
  		pid := os.Getpid()
  		out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -b -p %v", pid)).Output()
  		if err != nil {
  			return 0, fmt.Errorf("calling lsof: %s", err)
  		}
  		// only count lines with our pid, avoiding warning messages from -b
  		lines := strings.Split(string(out), strconv.Itoa(pid))
  		return len(lines), nil
  	case "windows":
  		// TODO: count open file handles on windows
  		return 0, errors.New("countOpenFiles() on Windows is not supported")
  	default:
  		return 0, errors.New("countOpenFiles() on this OS is not supported")
  	}
  }
docs: // countOpenFiles on operating systems that support lsof.