awk-script for getting processtime 
Author Message
 awk-script for getting processtime

Hello,
can someone help me ?
I have to write an awk-script for getting the ten processes using most of
the CPU-Time!
I don't know how to begin?

Thanks a lot!



Tue, 09 Jul 2002 03:00:00 GMT  
 awk-script for getting processtime


Quote:
> Hello,
> can someone help me ?
> I have to write an awk-script for getting the ten processes using most
of
> the CPU-Time!
> I don't know how to begin?

I don't remember what coulmn in ps output that holds the time. Say it's
column 5:

ps ax | tail +1 | awk '
NR > 1 {
  for (i = 1; i <= 10; i++)
    if ($5 > times[i]) {
       times[i] = $5
       processes[i] = $0
       break
    }

Quote:
}

END {
  for (p in processes)
    print processes[p]

Quote:
} '

I don't have a Unix prompt handy to test it. Maybe it'll take a little
more to get $5 (or whatever column it is) to a number suitable for the
compare. But something like this should work I think. The idea is
that the processes array should keep the 10 highest and then you print
it.

Hope it helps,
/Peter
--
-= Spam safe(?) e-mail address: pez68 at netscape.net =-

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 10 Jul 2002 03:00:00 GMT  
 awk-script for getting processtime

% I have to write an awk-script for getting the ten processes using most of
% the CPU-Time!
% I don't know how to begin?

Not a great awk application, in my opinion. If ps on your system supports
the -o switch, you can do this with ps, sort, and head:
  ps -eo pcpu,pmem,pid,command | sort -nr | head 11
--

Patrick TJ McPhee
East York  Canada



Wed, 10 Jul 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting A Day Using AWK or A Shell Script

2. getting pid in running awk script

3. Creating an awk script to extract other scripts from a file

4. Access to Script Name Within Awk Script

5. How to get Processtime ?

6. Getting awk computed value into shell variable

7. Getting shell variables into awk

8. Passing and getting vars. from C to awk

9. Getting awk (or sed or anything else) to put single quotes into file

10. Getting DATE/TIME in awk

11. Getting awk to ignore specified fields???

12. Replacing a string from an input file within awk script

 

 
Powered by phpBB® Forum Software