我试图创建一个脚本来显示 mysqld 的每个进程和子进程的使用量。您可以在我的代码中看到我做了什么。
#!/bin/bash
#file contains the output of: pstree mysql -a -p |awk '{print $1;}' | sed 's/|- {mysqld},//' >> psadd
filename='psadd'
#total= '0'
echo Start
while read p; do
memU= cat /proc/$p/smaps |grep -e Private -e Shared |awk '{print $2}' |awk '{total = total + $1}END{print total}'
echo "Process ID:"$p "Memory Usage:"$memU
total="$((total+memu))"
echo "This is the current running total:" $total
done < $filename
echo "Total=" $total
如果您有任何想法,我们将不胜感激。
计算进程的内存使用量是...复杂的。我通常使用进程的 RSS——驻留集大小——进程在内存中保存的、不被其他进程共享的内存量。
下面找到MySQL守护进程的进程ID,并使用ps
输出不带标题的 RSS 值。最后将其乘以四以获得以 KiB 为单位的 RSS 大小。 (默认页面大小为 4 KiB。)
ps有海量信息——玩得开心!
shell
ps -o rss= -p `pidof mysqld` | awk '{print $1*4, "KiB"}'
output
7808 KiB
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)