如何在linux中查找特定进程每5秒的内存消耗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14641553/
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
How to find the memory consumption of a particular process in linux for every 5 seconds
提问by Vamsi
I just want to know how to find the memory consumption of a particular process for particular time(say 5 seconds)
我只想知道如何找到特定时间(比如 5 秒)特定进程的内存消耗
I am new to linux. So, detailed steps of doing that will be appreciated
我是 linux 新手。因此,将不胜感激这样做的详细步骤
采纳答案by Roselyn Verbo Domingo
you may use SNMP to get the memory and cpu usage of a process in a particular device in network :)
您可以使用 SNMP 来获取网络中特定设备中进程的内存和 CPU 使用情况:)
Requirements:
要求:
- the device running the process should have snmp installed and running
- snmp should be configured to accept requests from where you will run the script below(it may be configured in snmpd.conf)
- you should know the process id(pid) of the process you want to monitor
- 运行该进程的设备应安装并运行 snmp
- 应该将 snmp 配置为接受来自您将在下面运行脚本的位置的请求(它可以在 snmpd.conf 中配置)
- 您应该知道要监视的进程的进程 id(pid)
Notes:
笔记:
HOST-RESOURCES-MIB::hrSWRunPerfCPUis the number of centi-seconds of the total system's CPU resources consumed by this process. Note that on a multi-processor system, this value may increment by more than one centi-second in one centi-second of real (wall clock) time.
HOST-RESOURCES-MIB::hrSWRunPerfMemis the total amount of real system memory allocated to this process.
HOST-RESOURCES-MIB::hrSWRunPerfCPU是此进程消耗的系统总 CPU 资源的厘秒数。请注意,在多处理器系统上,此值可能会在实际(挂钟)时间的 1 厘秒内增加超过 1 厘秒。
HOST-RESOURCES-MIB::hrSWRunPerfMem是分配给该进程的实际系统内存总量。
**
**
Process monitoring script:
进程监控脚本:
**
**
echo "IP: "
read ip
echo "specfiy pid: "
read pid
echo "interval in seconds:"
read interval
while [ 1 ]
do
date
snmpget -v2c -c public $ip HOST-RESOURCES-MIB::hrSWRunPerfCPU.$pid
snmpget -v2c -c public $ip HOST-RESOURCES-MIB::hrSWRunPerfMem.$pid
sleep $interval;
done
回答by mdunsmuir
This previously posted question:
这个以前发布的问题:
How to measure actual memory usage of an application or process?
seems like it may thoroughly address your question.
似乎它可以彻底解决您的问题。
edit: My personal favorite Linux utility for checking the resource usage of processes is top, though it can be misleading for reasons that are explained in the question I linked.
编辑:我个人最喜欢的用于检查进程资源使用情况的 Linux 实用程序是顶级的,尽管由于我链接的问题中解释的原因,它可能会产生误导。
回答by 0x90
回答by dward
Use top -p PID
where PID is the process ID. Information about the process should be displayed, including percent of system memory used. Type d
and an integer in seconds to change the refresh rate.
使用top -p PID
其中 PID 是进程 ID。应该显示有关进程的信息,包括使用的系统内存百分比。键入d
和一个以秒为单位的整数以更改刷新率。