22. Lsof

22.1. Why

As of 2006/Aug/29 there appears to be no lsof wrapper module available from CPAN.

22.2. Usage

Here are two examples of usage of Wrappers::Lsof.

As used by IDM_proc.pm:

    my $lsof  = Lsof->new(FLAGS => "+M", LOG => $self->{LOG});
    my $procs = $lsof->procs();

    foreach my $p (keys %$procs) {
        .
        .
        unless ($lsof->proc_attrib(PROC=>$p, ATTRIB=>"UNAME") eq "root") {  next;  }
        .
        .

As used by IDM_net_conns.pm:

    my $lsof  = Lsof->new(FLAGS => "-i4TCP", LOG => $self->{LOG});
    my $procs = $lsof->procs();

    foreach my $p (keys %$procs) {
        foreach my $f (keys %{$lsof->open_files(PROC => $p)}) {

            my $c = {};

            $c->{COMMAND} = $lsof->proc_attrib(PROC=>$p, ATTRIB=>"COMMAND");
            $c->{UNAME}   = $lsof->proc_attrib(PROC=>$p, ATTRIB=>"UNAME");

            $c->{LOCAL_HOST}  = $lsof->file_attrib(PROC=>$p, FILE=>$f, ATTRIB=>"LOCAL_HOST");
            $c->{LOCAL_PORT}  = $lsof->file_attrib(PROC=>$p, FILE=>$f, ATTRIB=>"LOCAL_PORT");
            $c->{REMOTE_HOST} = $lsof->file_attrib(PROC=>$p, FILE=>$f, ATTRIB=>"REMOTE_HOST");
            .
            .

22.3. To-Do

Make into a fully-functioning, CPAN-style module.

22.4. Hacking

Thankfully output from lsof seems to be more-or-less platform-independent, so the module should work out-of-the-box on most *nix platforms. More functionality should be trivial to add.



...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_cheesewire/_reml_grp/index.reml
On: 4/9/2006 at 17:35:44
Options: reml2 -i noindex -l long -o html -p multiple