In linux, the/proc/$ PID/status file provides the usage of the Process resources (memory, stack, semaphore, sub-parent process, although linux provides a lot of memory viewing commands, they all look at the overall usage and cannot view the memory usage of a single process.
This script is provided in this Article. You can view the VmRSS field in the status file to view the memory usage of the system or process. If you need it, refer to it.
Copy codeThe Code is as follows :#! /Bin/bash
Echo-n "PidName">/root/script/pid. f
Echo "MeMery">/root/script/pid. f
PIDPATH =/proc/
TOTLE = 0
Cd $ PIDPATH
DOC = 'LS'
For DOCNAME in $ DOC
Do
If [-d $ DOCNAME]; then
Cd $ DOCNAME
If [-f status]; then
MEMERY = 'grep VmRSS status | awk-F': ''{print $2} '| awk' {print $1 }''
PIDNAME = 'grep Name status | awk-F': ''{print $2 }''
If [$ MEMERY]; then
Echo-n $ PIDNAME>/root/script/pid. f
Echo-n "">/root/script/pid. f
Echo $ MEMERY>/root/script/pid. f
TOTLE = 'expr $ TOTLE + $ MEMERY'
Cd ..
Else
Cd ..
Fi
Else
Cd ..
Fi
Fi
Done
TOTLE = 'expr $ TOTLE/100'
Echo "totle userd: $ totle mb">/root/script/pid. f
Cat/root/script/pid. f