查看 auditd 服务的内存,单位 mb
ps -eo pid,%mem,rss,comm | grep auditd | grep -v grep | awk '{rss_mb = $3 / 1024; printf "pid: %-6s 内存占比: %-5s 物理内存: %.2f mb 进程名: %s\n", $1, $2"%", rss_mb, $4}'
输出效果:
pid: 1234 内存占比: 2.5% 物理内存: 256.30 mb 进程名: auditd
ps 命令查看内存排行
ps aux --sort=-%mem | head -n 10
输出效果:
[root@fkfwq1 system]# ps aux --sort=-%mem | head -n 10 user pid %cpu %mem vsz rss tty stat start time command root 1233758 30.1 8.7 16119744 2725092 pts/3 sl 10:28 10:49 java -jar /myfile/auxiliary_v1.0/qx-auxiliary-v1.0.jar mysql 3426079 0.2 1.6 3345780 502028 ? ssl 8月22 280:51 /usr/sbin/mysqld root 3905935 0.0 1.5 3100580 493380 ? sl 10月21 10:30 /usr/local/lib64/mate-indicators/libexec/mate-indicators root 778 0.1 0.6 271612 198532 ? ss 8月14 172:41 /usr/lib/systemd/systemd-journald root 9137 0.2 0.5 841588 177924 ? sl 8月14 293:11 /usr/local/bin/python3 qxfk_sub1500.py -u emqx 5707 0.5 0.2 4168940 84776 pts/1 ssl+ 8月14 573:08 /usr/lib/emqx/erts-10.7/bin/beam.smp -p 2097152 -q 1048576 -e 256000 -spp true -a 4 -iot 4 -sdio 8 -- -root /usr/lib/emqx -progname usr/bin/emqx -- -home /var/lib/emqx -- -boot /usr/lib/emqx/releases/4.2.14/emqx -mode embedded -boot_var erts_lib_dir /usr/lib/emqx/erts-10.7/../lib -mnesia dir "/var/lib/emqx/mnesia/emqx@127.0.0.1" -config /var/lib/emqx/configs/app.2025.08.14.10.13.57.config -kernel net_ticktime 120 -shutdown_time 30000 -setcookie emqxsecretcookie -name emqx@127.0.0.1 -- -vm_args /var/lib/emqx/configs/vm.2025.08.14.10.13.57.args -start_epmd false -epmd_module ekka_epmd -proto_dist ekka -- console -- root 9216 1.4 0.1 1877248 34308 ? sl 8月14 1626:22 /usr/local/bin/python3 qxfk_read1500_fan.py -u root 1242 0.1 0.1 684792 33676 ? ssl 8月14 120:36 /usr/sbin/rsyslogd -n -inone root 9217 1.4 0.1 2532352 33140 ? sl 8月14 1632:24 /usr/local/bin/python3 qxfk_read1500_nofan.py -u [root@fkfwq1 system]#
通过进程的工作目录(cwd)定位文件的位置
[root@fkfwq1 myfile]# ps -ef|grep python root 1389 1 0 8月14 ? 00:08:31 /usr/bin/python3 /usr/sbin/lvmdbusd root 1422 1 0 8月14 ? 00:00:00 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid root 2060 1 0 8月14 ? 00:10:21 /usr/bin/python3 -es /usr/sbin/tuned -l -p root 9137 1 0 8月14 ? 04:53:59 /usr/local/bin/python3 qxfk_sub1500.py -u root 9216 1 1 8月14 ? 1-03:10:55 /usr/local/bin/python3 qxfk_read1500_fan.py -u root 9217 1 1 8月14 ? 1-03:16:58 /usr/local/bin/python3 qxfk_read1500_nofan.py -u root 9767 9461 0 8月14 ? 00:00:00 /usr/bin/python3 /usr/local/lib64/mate-indicators/libexec/reset_applet_position.py root 10109 9452 0 8月14 ? 00:53:13 python2 /usr/lib/ubuntu-mate/mate-menu/mate-menu.py root 1699343 1600094 0 15:54 pts/3 00:00:00 grep python [root@fkfwq1 myfile]# [root@fkfwq1 myfile]# ls -l /proc/9137/cwd lrwxrwxrwx 1 root root 0 10月 29 15:54 /proc/9137/cwd -> /myfile/project_python [root@fkfwq1 myfile]#
查看服务的位置

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
 
             我要评论
我要评论 
                                             
                                             
                                             
                                             
                                             
                                            
发表评论