#!<> use INSTALL::common; use INSTALL::parameter; use INSTALL::os; use INSTALL::process_info; my $pParameters = \%INSTALL::parameter::variables; #============================================================================== #------------------------ Default global values #============================================================================== my $pOS = \%INSTALL::os::Details; #Process format: # # # [0-9]+ # [0-9]+ # "[full path to binary name]" # "[name of binary (without path)]" # [0-9]+ # [0-9]+ # [0-9]+ # [0-9]+ # [allocated virtual memory size] # [allocated real (resident) memory size] # [memory size which is shared] # # "[argument 0]" # "[argument 1]" # "[argument 2]" # ... # # # ... # open(OUTPUT,">&STDOUT"); sub dump_process { ($#_ == 0) || die "Invalid number of arguments."; my ($pid) = @_; my %process_info = INSTALL::process_info::process_info($pid); if (scalar(keys %process_info)) { print OUTPUT ( " \n", " $process_info{pid} \n", " $process_info{ppid} \n", " \"$process_info{binary}\" \n", " \"$process_info{name}\" \n", " $process_info{ruid} \n", " $process_info{euid} \n", " $process_info{rgid} \n", " $process_info{egid} \n", " $process_info{vmsize} \n", " $process_info{residentsize} \n", " $process_info{sharedsize} \n", " \n", map ( " \"$_\" \n", @{$process_info{pArgv}} ), " \n", " \n" ); } else { return(undef); } } sub build_process_info { ($#_ < 0) || die "Invalid number of arguments."; my %prochash = INSTALL::process_info::retrieve_prochash; my (@procs,@names); @procs = keys %prochash; @names = map { s@^.*/([^/]+)$@$1@; $_ } values %prochash; # print "Process pid list:\n ",join(" ",map("$_\n",@procs)),"\n"; # print "Process name list:\n ",join(" ",map("$_\n",@names)),"\n"; return(\@procs,\@names); } sub usage { print STDERR ("Usage: $0 \n", "Arguments:\n", " [pid=[,,...,]]\n", " [name=[,,...,]]\n", "\n", "Note: If both pid and name is specified, the results will be the union\n", " of the pids listed with the pids of those processes with names\n", " matching those in the names listed.\n", "\n"); exit(1); } sub main { if (scalar(keys %$pParameters)) { (grep { ($_ eq "pid") || ($_ eq "name") } keys %$pParameters) || usage; } my (@procs,@names); if (exists $pParameters->{pid}) { my $pids = $pParameters->{pid}; while(length($pids)) { if ($pids =~ s/^([0-9]+),?//) { push @procs,$1; } else { print STDERR ("Error: Invalid pid list."); usage(); } } } if (exists $pParameters->{name}) { my $names = $pParameters->{name}; while(length($names)) { if ($names =~ s@^((\\.|[^,])+),?@@) { push @names,$1; } else { print STDERR ("Error: Invalid name list."); usage(); } } } my ($pProcs, $pNames) = build_process_info; if (not ((exists $pParameters->{name}) or (exists $pParameters->{pid}))) { @procs = @$pProcs; } else { if (exists $pParameters->{name}) { # Match names agains $pNames, record indexes. my @indexes; foreach(@names) { my $name = $_; for(my $i=0; $i < scalar(@$pNames); $i++) { if ($pNames->[$i] eq $name) { push @indexes, $i; } } } my @addedprocs = map($pProcs->[$_],@indexes); @procs = sort(@procs,@addedprocs); } } print OUTPUT ("\n"); my $result = 0; foreach(@procs) { $result |= dump_process($_); } print OUTPUT ("\n"); return($result); } exit(not main);