#!/usr/sup/gnu/bin/perl # Copyright (C) 1995, Mats Kindahl. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # E-mail: matkin@docs.uu.se # # Program to compute process statistics for each user who has a # process on the system. open(PS, "/usr/bin/ps aux|") || die "Could not fork process!\n"; $format = 'A9 A5 A5 A5 A5 A5 A3 A5 A7 A5 A*'; $header = ; @name = unpack($format, $header); foreach (@name) { tr/ //d; } while () { @value = unpack($format, $_); foreach $i (1..5) { $Data{$value[0]}{$name[$i]} += $value[$i]; } } close PS; foreach $user (sort { $Data{$b}{SZ} <=> $Data{$a}{SZ} } keys %Data) { $D = $Data{$user}; write; } format STDOUT_TOP = User Size %CPU %MEM Res. Size ------------------------------------------------------ . format STDOUT = @<<<<<<<<<<<<<< @>>>>>> @>>>>>> @>>>>>>> @>>>>>>>>>>> $user, @$D{SZ,'%CPU','%MEM',RSS} .