dongzhoulong1797
dongzhoulong1797
2015-05-04 01:19
浏览 215
已采纳

如何在GO中获取总内存/ RAM?

How can I get the total amount of memory/RAM attached to a system in Go? I want to use native code only if possible. I have found a library that wraps linux sysinfo command. Is there a more elegant way?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doukong1901
    doukong1901 2015-05-04 01:28
    已采纳

    Besides runtime.MemStats you can use gosigar to monitor system memory.

    点赞 评论
  • dr200166
    dr200166 2015-08-26 18:59

    cgo & linux solution

    package main
    
    // #include <unistd.h>
    import "C"
    
    func main() {
        println(C.sysconf(C._SC_PHYS_PAGES)*C.sysconf(C._SC_PAGE_SIZE), " bytes")
    }
    
    点赞 评论

相关推荐