memsize_netbsd.go 607 B

123456789101112131415161718192021222324252627282930
  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 https://mozilla.org/MPL/2.0/.
  6. package ur
  7. import (
  8. "os/exec"
  9. "strconv"
  10. "strings"
  11. )
  12. func memorySize() int64 {
  13. cmd := exec.Command("/sbin/sysctl", "hw.physmem64")
  14. out, err := cmd.Output()
  15. if err != nil {
  16. return 0
  17. }
  18. fs := strings.Fields(string(out))
  19. if len(fs) != 3 {
  20. return 0
  21. }
  22. bytes, err := strconv.ParseInt(fs[2], 10, 64)
  23. if err != nil {
  24. return 0
  25. }
  26. return bytes
  27. }