Monitoring CPU Process Usage

Scott Bowling sbowling at bowlingkyler.com
Mon Nov 11 04:15:29 CST 2002


Well, let's see.  I might be able to write a bit of code to add to the cgi
program to log this information right before it ends, but is there a way to
log this information outside of the script?

In other words, is there a way to get this information without knowing the
PID?  I want to key off of program name or even user name?

Would it be possible to write some sort of process monitoring system that is
capable of retrieving this information after the process ends (or maybe
right before the process ends)?

I haven't really messed around with the system in this respect before, so
any help is much appreciated.

Thanks!
Scott

On 11/10/02 12:14 PM, "Duane Attaway" <dattaway at attaway.net> wrote:

> On Sun, 10 Nov 2002, Scott Bowling wrote:
> 
>> I've got a CGI script that I'd like to determine how much CPU usage it uses
>> over a period of time... let's say for a week.
> 
> cat /proc/<process id>/stat
> 
> We can get exactly what you need down to each 1/100th of a second right
> from the /proc directory. And the best recepie for this is straight from
> the command line, perfect for scripting.  The /proc/stat entry will serve
> you these juicy morsels (from the proc manpage:)
> 
>      stat   kernel/system  statistics.   Varies  with architec-
>             ture.  Common entries include:
> 
>             cpu  3357 0 4313 1362393
>                    The number of jiffies (1/100ths of a second)
>                    that  the  system  spent  in user mode, user
>                    mode with low priority (nice), system  mode,
>                    and  the  idle task, respectively.  The last
>                    value should be 100 times the second entry in the
>                    uptime pseudo-file.
> 
> 
> Of course, stat will give you more than just those four numbers, but the
> man page lists all the values given, in order. The two values you might be
> interested in (with the scanf code:)
> 
>                    cutime %ld
>                            The number of jiffies that this pro-
>                            cess  and  its  children  have  been
>                            scheduled in user mode.
> 
>                    cstime %ld
>                            The number of jiffies that this pro-
>                            cess  and  its  children  have  been
>                            scheduled in kernel mode.
> 
> 
> 
> 




More information about the Kclug mailing list