#!/usr/bin/perl

# a handy little utility for generating a count of how many of each name of process are running
# takes one argument, the threshold above which to report on


$pc = shift || 5;

open(PS,"ps -A|");


while($in = <PS>) {
	chop($in);
	
	$in = " $in";

	@psres = split(/ +/,$in);

	#for($i=0;$i<@psres;$i++) {
	#	print "$i:" . $psres[$i] . "\n";
	#}

	$cc = $psres[4];

	if(defined $proc{$cc}) {
		$proc{$cc}++;
	} else {
		$proc{$cc} = 1;
	}

}

foreach $process (keys %proc) {
	$count = $proc{$process};

	if($count > $pc) {
		print "$process:\t\t\t\t$count\n";
	}
}


