【发布时间】:2013-07-29 06:56:49
【问题描述】:
我喜欢这样的 shell 脚本:
while true;do
curl -s example.com | egrep -o 'sth'
sleep 60
done
如何在运行时获取进程 bash 和 curl 和 egrep 和 sleep 的总内存使用量?
【问题讨论】:
标签: shell memory monitoring
我喜欢这样的 shell 脚本:
while true;do
curl -s example.com | egrep -o 'sth'
sleep 60
done
如何在运行时获取进程 bash 和 curl 和 egrep 和 sleep 的总内存使用量?
【问题讨论】:
标签: shell memory monitoring
你可以使用 ps 命令:
ps aux | grep <scriptName>
ps aux | grep "curl -s example"
ps aux | grep "egrap -s 'sth'"
ps aux | grep "sleep 60"
第 3 列和第 4 列是 cpu 和 mem(您可以使用 awk 获取它们)
【讨论】:
ps axu | grep -e <scriptname> -e "curl -s example" -e "egrep -s 'sth'" -e "sleep 60" | cut -f3,4。即使您希望代码跨越多行(例如出于美观原因),您仍然可以通过以反斜杠 (``) 结束除最后一行之外的所有行来执行此操作,但是您只启动一个 grep 实例而不是四个实例。