用smem命令查看linux下进程对物理内存的占用

我们都知道linux命令有很多,但在linux下要准确的计算一个进程实际使用的物理内存是多少却不是那么的简单,今个我就介绍个简单,方便,明了的工具命令smem.
Smem命令:
背景:smem是一款命令行下的内存使用情况报告工具,它能够给用户提供Linux系统下的内存使用的多种报告。
不废话了,干
依赖安装:
[root@node02 ~]# yum install epel-release
[root@node02 ~]# yum install smem python-matplotlib python-tk
要显示系统中的每个进程的占用内存状态,可执行如下命令:
[root@node02 ~]# smem -K -s uss
PID User Command Swap USS PSS RSS
4642 root /sbin/agetty --noclear tty1 0 168 207 868
4633 root /usr/sbin/crond -n 0 672 724 1620
4560 root /sbin/auditd 0 704 734 1300
4630 root /usr/lib/systemd/systemd-lo 0 800 848 1756
2385 root /usr/lib/systemd/systemd-ud 0 852 929 1896
4604 dbus /usr/bin/dbus-daemon --syst 0 760 1005 2340
5106 root /usr/libexec/postfix/master 0 1148 1215 2172
7134 postfix pickup -l -t unix -u 0 1184 1578 4088
5122 postfix qmgr -l -t unix -u 0 1228 1622 4132
4892 root /usr/sbin/sshd -D 0 1024 1627 4356
4631 root /usr/bin/abrt-watch-log -F 0 1488 2202 4836
7473 root -bash 56 2184 2244 3060
2379 root /usr/sbin/lvmetad -f 0 2588 2674 3620
4591 root /usr/sbin/abrtd -d -s 0 2156 2905 5744
2356 root /usr/lib/systemd/systemd-jo 0 1584 3114 5544
1 root /usr/lib/systemd/systemd -- 0 3040 3174 4300
7465 root sshd: root@pts/0 8 2560 3231 6104
4589 root /usr/bin/vmtoolsd 0 2512 3268 6308
4588 root /usr/bin/VGAuthService -s 0 2664 3392 6268
7818 root python /usr/bin/smem -K -s 0 5712 6414 7920
4629 polkitd /usr/lib/polkit-1/polkitd - 0 7760 8185 10516
4888 root /usr/bin/python2 -Es /usr/s 20 12452 13724 17308
4902 root /usr/bin/containerd 0 29640 29736 30500
4894 root /usr/bin/dockerd -H fd:// 0 58600 58755 59840
4893 root /usr/sbin/rsyslogd -n 120 106416 107983 110672
注释:
参数-K:用来显示内存单位
参数-s: 排序
Uss:对uss列进行排序,输出系统中所有系统进行占用内存的大小

也可用百分号的形式显示每个进程的占用系统内存的比率,如下图所示:
[root@node02 ~]# smem -p -s uss
PID User Command Swap USS PSS RSS
4642 root /sbin/agetty --noclear tty1 0.00% 0.01% 0.01% 0.05%
4633 root /usr/sbin/crond -n 0.00% 0.04% 0.04% 0.09%
4560 root /sbin/auditd 0.00% 0.04% 0.04% 0.07%
4604 dbus /usr/bin/dbus-daemon --syst 0.00% 0.04% 0.05% 0.12%
4630 root /usr/lib/systemd/systemd-lo 0.00% 0.04% 0.05% 0.09%
2385 root /usr/lib/systemd/systemd-ud 0.00% 0.05% 0.05% 0.10%
4892 root /usr/sbin/sshd -D 0.00% 0.05% 0.09% 0.23%
5106 root /usr/libexec/postfix/master 0.00% 0.06% 0.06% 0.12%
7134 postfix pickup -l -t unix -u 0.00% 0.06% 0.08% 0.22%
5122 postfix qmgr -l -t unix -u 0.00% 0.07% 0.09% 0.22%
4631 root /usr/bin/abrt-watch-log -F 0.00% 0.08% 0.12% 0.26%
2356 root /usr/lib/systemd/systemd-jo 0.00% 0.08% 0.15% 0.27%
4591 root /usr/sbin/abrtd -d -s 0.00% 0.11% 0.15% 0.31%
7473 root -bash 0.00% 0.12% 0.12% 0.16%
4589 root /usr/bin/vmtoolsd 0.00% 0.13% 0.17% 0.34%
7465 root sshd: root@pts/0 0.00% 0.14% 0.17% 0.32%
2379 root /usr/sbin/lvmetad -f 0.00% 0.14% 0.14% 0.19%
4588 root /usr/bin/VGAuthService -s 0.00% 0.14% 0.18% 0.33%
1 root /usr/lib/systemd/systemd -- 0.00% 0.16% 0.17% 0.23%
7917 root python /usr/bin/smem -p -s 0.00% 0.30% 0.34% 0.42%
4629 polkitd /usr/lib/polkit-1/polkitd - 0.00% 0.41% 0.43% 0.56%
4888 root /usr/bin/python2 -Es /usr/s 0.00% 0.66% 0.73% 0.92%
7911 root /opt/etcd/bin/etcd --name=e 0.00% 1.57% 1.57% 1.57%
4902 root /usr/bin/containerd 0.00% 1.57% 1.58% 1.62%
4894 root /usr/bin/dockerd -H fd:// 0.00% 3.11% 3.12% 3.18%
4893 root /usr/sbin/rsyslogd -n 0.00% 5.67% 5.74% 5.88%
注释:
参数-p:以百分号的形式报告内存的使用情况

显示系统中的每一个用户的内存使用情况:
[root@node02 ~]# smem -u -k
User Count Swap USS PSS RSS
dbus 1 0 760.0K 1005.0K 2.3M
postfix 2 0 2.4M 3.1M 8.0M
polkitd 1 0 7.6M 8.0M 10.3M
root 22 192.0K 259.8M 268.8M 303.9M
注释:
参数-u:用户

转载于:https://blog.51cto.com/8593714/2354363

你可能感兴趣的:(用smem命令查看linux下进程对物理内存的占用)