如何每5秒查找一次linux中特定进程的内存消耗 [英] How to find the memory consumption of a particular process in linux for every 5 seconds
问题描述
我只想知道如何查找特定进程在特定时间(例如5秒)的内存消耗
I just want to know how to find the memory consumption of a particular process for particular time(say 5 seconds)
我是Linux新手.因此,我们将感谢您执行此操作的详细步骤
I am new to linux. So, detailed steps of doing that will be appreciated
推荐答案
您可以使用SNMP获取网络中特定设备中进程的内存和CPU使用率:)
you may use SNMP to get the memory and cpu usage of a process in a particular device in network :)
要求:
- 运行该进程的设备应已安装并正在运行snmp
- snmp应该配置为从下面运行脚本的位置接受请求(可能在snmpd.conf中配置)
- 您应该知道要监视的进程的进程ID(pid)
注释:
-
HOST-RESOURCES-MIB :: hrSWRunPerfCPU 是此过程消耗的总系统CPU资源的厘秒数.请注意,在多处理器系统上,此值可能会在实际(挂钟)时间的1厘秒中增加1厘秒以上.
HOST-RESOURCES-MIB::hrSWRunPerfCPU is 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 :: hrSWRunPerfMem 是分配给该进程的实际系统内存总量.
HOST-RESOURCES-MIB::hrSWRunPerfMem is the total amount of real system memory allocated to this process.
**
过程监视脚本:
**
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
这篇关于如何每5秒查找一次linux中特定进程的内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!