hi all

 

I refer to the following page and correct it somewhole , ,Your comments and
suggestions are welcome , thanks .

http://www.cpan.org/authors/id/S/SU/SUJAI/Process-Detail-0.1.pl

 

 

the code:

 

#!/usr/bin/perl 

 

use warnings;

use strict;

use Switch;

 

my $VERSION=0.1;

 

my $dir="/proc";

opendir DIR,$dir or die "opendir $dir err:$!";

 

sub hidden {

        print "#" x 10 . "Hidden processlist" . "#" x 10 . "\n";

        foreach my $pcs (readdir DIR) {

                if ($pcs=~/\d+/ && $pcs=~/\./) {

                        &detailedview("$pcs");

                }

        }

}

 

sub all {

        foreach my $pcs (readdir DIR) {

                if ($pcs=~/\d+/) {

                        &detailedview("$pcs");

                }

        }

}

 

sub detailedview {

        my @ar...@_;

        my $envir="/proc/$args[0]/environ";

        my $stat="/proc/$args[0]/status";

        open CMD,"/proc/$args[0]/cmdline" or die "open CMD err:$!";

        print "PID=$args[0]\n";

        while (<CMD>) {

                print "COMMAND=$_\n";

        }

 

open FILE,"< $envir" or die "$!";

while (<FILE>) {

        my @array=split /([A-Z]+(_|[A-Z])+\=.[^A-Z]+)/,$_;

        foreach my $splitted (@array) {

                if ($splitted=~/\=/) {

                        print "$splitted\n";

        }

        }

}

close FILE;

 

open FILESTAT,"< $stat" or die "$!";

while (<FILESTAT>) {

        if (/(Name|State|PPid|Gid|Uid)/) {

                print;

        }

}

close FILESTAT;

 

print "-" x 50 . "\n";

}

 

sub usage {

        print "\nUsage:

                -h\t For detailed view hidden process

                -a\t For detailed view of all processes

                -p\t For detailed view of process with process pid

                --help\t For help

                -V\t For checking Version\n\n";

}

 

if ($#ARGV lt 0) {

        &usage;

        exit;

} else {

        switch ($ARGV[0]) {

                case "-h" {&hidden;}

                case "-p" {&detailedview($ARGV[1]);}

                case "-a" {&all;}

                case "--help" {&usage;}

                case "-V" {print "\nProcess-Detail Version $VERSION\n\n"}

                else {&usage;}

        }

}

 

Reply via email to