#!/usr/bin/perl -w ##Copyright yours truly Ilian Z. use strict; sub handler { print "Interupt catch\n"; die "Dead...\n"; } =pod open LS, "ps aux|" or die "Can`t open filehandle: $!\n"; my %phash=(); my $strm; while ( ) { { print "#enter the block"; if ( $strm ) { last; } $strm = index($_, "STAT"); } if ( /^.{$strm}(?.{1,4}\s){1}?/i ) { $phash{$+{status}}++; } } close LS; while ( my($k, $v) = each(%phash) ) { print $k, " ===> ", $v, "\n"; } =cut open TOP, "top|" || die "Can`t open 'top' command: $!\n"; my %pnc = (); my @tmp=(); my ($pid, $command); while ( my $match = ) { { next if $command > 0 ; $command = index($match, "COMMAND"); $command++; # end block after 1st verify } next if $command < 1 ; #if we don`t match the index let`s skip below #Here we make a process ID the key and the command the value #a bit ugly but normal for Camel ($pnc{($match =~ /(?\d+)/) ? $+{pid} : 0} = ($match =~ /^.{$command}\s(?.+)/i)?$+{cmd} : 0 ) || next; } close TOP; while ( my ($k, $v) = each(%pnc) ) { if ( defined $k and defined $v ) { print "Proc.ID#",$k," runs command: ", $v,"\n"; } }