How can I find out the total physical memory (RAM) of my linux box suitable to be parsed by a shell script?

前端 未结 13 1792
梦如初夏
梦如初夏 2020-12-07 09:52

I\'m typing a shell script to find out the total physical memory in some RHEL linux boxes.

First of all I want to stress that I\'m interested in the total ph

相关标签:
13条回答
  • 2020-12-07 10:19

    These are the ways :

    1. /proc/meminfo

    MemTotal: 8152200 kB
    
    MemFree: 760808 kB
    

    You can write a code or script to parse it.

    2. Use sysconf by using below macros

    sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGESIZE);

    3. By using sysinfo system call

    int sysinfo(struct sysinfo *info);

    struct sysinfo { .

       .
    
       unsigned long totalram;  /*Total memory size to use */
    
       unsigned long freeram;   /* Available memory size*/
    
       .
    
       . 
    
      }; 
    
    0 讨论(0)
提交回复
热议问题