Linux 如何随时间监控进程内存使用情况 - ubuntu

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7278326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:00:00  来源:igfitidea点击:

how to monitor a processes memory usage over time - ubuntu

linuxmemoryubuntumonitoring

提问by Joelio

I want to watch a given process in unix over time to see what time memory grows (its a long running job)

我想随着时间的推移在 unix 中观察给定的进程,以查看内存增长的时间(这是一项长期运行的工作)

I guess I could do

我想我能做到

ps -aux | grep PID

and run this from cron every 5 minutes, but it seems there should be a better way.

每 5 分钟从 cron 运行一次,但似乎应该有更好的方法。

Is there a way I can use sar to do this?

有没有办法可以使用 sar 来做到这一点?

采纳答案by holygeek

I use the following:

我使用以下内容:

$ ps -o rss $(pgrep executablename)

Put that in a while loop or use watch to monitor it over time coupled with tail. You can also tee it to a file and have gnuplot plot it for you and refresh it every few seconds.

把它放在一个 while 循环中或使用 watch 来监视它随着时间的推移加上 tail。您也可以将它发送到一个文件中,并让 gnuplot 为您绘制它并每隔几秒钟刷新一次。