in reply to Finding out Processor Usage

uptime is reasonably portable across Unices and is simple to parse:
my $info = `uptime`; ($avg_1, $avg_5, $avg_15) = $info =~ /load average:\s+(\S+),\s+(\S+),\ +s+(\S+)/; print "$avg_1, $avg_5, $avg_15\n";

-Mark

Replies are listed 'Best First'.
Re: Re: Finding out Processor Usage
by tachyon (Chancellor) on Apr 11, 2004 at 00:32 UTC
Re: Re: Finding out Processor Usage
by stvn (Monsignor) on Apr 10, 2004 at 23:32 UTC

    I looked at uptime, but i wasnt sure how its output relates to CPU percentage, like which is output by top. Do you have any insight into this? Thanks.

    -stvn

      uptime is the same as the first line of top(1) or w(1). Load average however (which is what is reported there) is not CPU usage. Load average is the average number of processes *waiting to run/running* over the last x period. The higher the load average the greater the load on the system as the OS queues processes for a time slice. This has a vague relation to CPU usage but that is all. See this for more details.

      cheers

      tachyon

      uptime will output the current time, the time the system has been up, the number of users connected and the load averages. The load averages are a condensation of the %usr, %sys and %wio cpu statistics at that given time. Where usr and sys represent the % cpu cycles dealing with user and system calls respectively and wio are the percentage of cycles that are bound on io waits.