memtotal_solaris.go 520 B

1234567891011121314151617181920212223242526
  1. package sysinfo
  2. /*
  3. #include <unistd.h>
  4. */
  5. import "C"
  6. // PhysicalMemoryBytes returns the total amount of host memory.
  7. func PhysicalMemoryBytes() (uint64, error) {
  8. // The function we're calling on Solaris is
  9. // long sysconf(int name);
  10. var pages C.long
  11. var pagesizeBytes C.long
  12. var err error
  13. pagesizeBytes, err = C.sysconf(C._SC_PAGE_SIZE)
  14. if pagesizeBytes < 1 {
  15. return 0, err
  16. }
  17. pages, err = C.sysconf(C._SC_PHYS_PAGES)
  18. if pages < 1 {
  19. return 0, err
  20. }
  21. return uint64(pages) * uint64(pagesizeBytes), nil
  22. }