This post was updated 822 days ago and some of the ideas may be out of date.
我有时候要查看一个进程的内存实时占用,记录一下命令。
提示ps命令不存在的需要安装procps
bash-5.1# ps
bash: ps: command not found
操作系统 | 包管理器 | 安装命令 |
---|---|---|
Debian Ubuntu Ubuntu Kylin Deepin | apt | sudo apt-get install -y procps libprocps-dev |
CentOS | yum | sudo yum install -y procps |
Alpine Linux | apk | sudo apk add procps |
Arch Linux ArcoLinux Manjaro Linux | pacman | sudo pacman -Syyu --noconfirm |
Gentoo Linux | Portage | sudo emerge procps |
ps配合awk、while命令就可以查看进程内存占用的实时情况
while true;do clear;echo "Date: $(date +'%Y-%m-%d %H:%I:%S')";ps aux|grep -E '(webman|php)'|grep -v grep|awk 'BEGAIN{totalMemory=0}{totalMemory+=$6;print $6/1024 "MB" "\t" $0}END{print "Total Memory:" totalMemory/1024 "MB"}';sleep 1;done
参与讨论