Results 1 to 6 of 6
Hi, I am trying to write a program in perl to calculate the cpu and processor utilization of a particular process (for example : mozilla). The output of the program ...
- 05-13-2007 #1
%CPU & %MEM utilization
Hi, I am trying to write a program in perl to calculate the cpu and processor utilization of a particular process (for example : mozilla). The output of the program must be just like the result obtained by ps command under linux, but i do not want to use the ps command in my program to get the cpu and memory details but use the /proc filesystem to calculate the cpu and memory utilization of process.
Can you help me how do i calculate the cpu and memory in percentage, utilized by a particular process from the /proc filesystem. I have learnt from various resources that ps command too uses /proc filesystem to get the information about processes, but i could not find any information of how to calculate the percentage utilization of cpu and memory of particular process.
I hope you could help me out of this problem.
Thank you.
- 05-14-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 05-14-2007 #3
Well, /proc/meminfo has information such as the total memory of the box.
/proc also has subdirectories for each running process. Each of these has a 'mem' file. Now, I seem to be unable to read mine, but these likely have information related to the memory usage of a particular process. If you can find a guide through /proc/PID/status, this may also have some info.Code:alex@danu /proc $ cat meminfo MemTotal: 1295048 kB MemFree: 141768 kB Buffers: 187912 kB Cached: 338496 kB SwapCached: 0 kB ...
DISTRO=Arch
Registered Linux User #388732
- 05-14-2007 #4
- 05-14-2007 #5
hi, i think you got my point. i found the information under /proc/PID/status but do you know how to i convert those values in to %values do you have any formlua to find the %cpu and %mem utilization using the values avilable in /proc/PID/stat or cpu or mem etc.,
thanks for you relpy
- 05-14-2007 #6
Alrighty, well, the proc man page has a great deal of information. In particular, it discusses the /proc/PID/stat file, where the 23rd entry is:
If you combine that bit of information with /proc/meminfo, you should be able to figure out percentages.Code:vsize %lu Virtual memory size in bytes.DISTRO=Arch
Registered Linux User #388732


Reply With Quote
