memsize_netbsd.go 676 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package main
  7. import (
  8. "errors"
  9. "os/exec"
  10. "strconv"
  11. "strings"
  12. )
  13. func memorySize() (int64, error) {
  14. cmd := exec.Command("/sbin/sysctl", "hw.physmem64")
  15. out, err := cmd.Output()
  16. if err != nil {
  17. return 0, err
  18. }
  19. fs := strings.Fields(string(out))
  20. if len(fs) != 3 {
  21. return 0, errors.New("sysctl parse error")
  22. }
  23. bytes, err := strconv.ParseInt(fs[2], 10, 64)
  24. if err != nil {
  25. return 0, err
  26. }
  27. return bytes, nil
  28. }