#!/usr/bin/perl use warnings; use strict; use Proc::ProcessTable; #usage: cpusage pid1 pid2 pid3..... #run without args to get full list #then run with chosen pids and it will update #every 5 secs. No output with invalid pids. my @pids=undef; my $t = new Proc::ProcessTable; @pids = @ARGV; #get pids to watch on commandline if (@pids){ while(1){ foreach my $p (@{$t->table}) { if(grep {$p->pid == $_}@pids){ print "--------------------------------\n"; print 'pid ',$p->pid,' ',$p->cmndline,' ','CPU% ',$p->{pctcpu},"\n"; } } sleep(5); } }else{ foreach my $p (@{$t->table}) { print "--------------------------------\n"; print 'pid ',$p->pid,' ',$p->cmndline,' ','CPU% ',$p->{pctcpu},"\n"; } } exit(0);