我想编写一个脚本来定期检查我的 RAM 使用情况,然后计算其最大值。
要计算已用内存,我有两个选择,通过neofetch或free -m
的输出给出$ free -m:
total used free shared buff/cache available
Mem: 15839 4169 7630 794 4039 10555
Swap: 2047 0 2047
Run Code Online (Sandbox Code Playgroud)
因此,我通过管道传输输出,$ free -m | grep Mem | awk '{print ($3/1024)}'结果为4.07324.
现在,如果我执行类似于$neofetch输出的操作$ neofetch | grep -i Memory | awk '{print ($2/1024)}',我得到的输出为4.84668
因此,这 2 个输出不匹配,应该考虑哪一个来检查实际 RAM 使用情况?如果重要的话,我有一个 4GB GTX1650 运行 Nvidia 驱动程序,并且53MB在通过检查时消耗 RAM$ nvidia-smi
我能想到的一种可能的情况是,哪里$ neofetch给了我已用内存和共享内存,因为
$ free …