Linux-Fuser
view release on metacpan or search on metacpan
lib/Linux/Fuser.pm view on Meta::CPAN
if ( ( $dev == $statinfo[0] ) && ( $ino == $statinfo[1] ) )
{
push @procinfo,Linux::Fuser::Procinfo->new($proc, $fd_data);
}
}
}
}
return @procinfo;
}
1;
package Linux::Fuser::Procinfo;
=back
=head2 PER PROCESS METHODS
The fuser() method will return a list of objects of type Linux::Fuser::Procinfo
which itself has methods to return information about the process.
=over 2
=item user
The login name of the user that started this process ( or more precisely
that owns the file descriptor that the file is open on ).
=item pid
The process id of the process that has the file open.
=item cmd
The command line of the program that opened the file. This actually returns
a reference to an array containing the individual elements of the command
line.
=item filedes
A Linux::Fuser::FileDescriptor object that has details of the file as
the process has it opened - see below.
=back
=cut
use strict;
use Carp;
use vars qw($AUTOLOAD);
sub new
{
my ( $class, $pid, $fd_data ) = @_;
my $fd = $fd_data->[0];
my $fd_no = $fd_data->[1];
my $user = getpwuid( ( lstat($fd) )[4] );
my @cmd = ('');
if ( open CMD, "/proc/$pid/cmdline" )
{
chomp( @cmd = <CMD> );
}
my $filedes = Linux::Fuser::FileDescriptor->new($pid, $fd_no);
my $procinfo = {
pid => $pid,
user => $user,
cmd => \@cmd,
filedes => $filedes
};
bless $procinfo, $class;
return $procinfo;
}
sub AUTOLOAD
{
my ( $self, @args ) = @_;
no strict 'refs';
( my $method = $AUTOLOAD ) =~ s/.*://;
return if $method eq 'DESTROY';
if ( exists $self->{$method} )
{
*{$AUTOLOAD} = sub {
my ( $self, @args ) = @_;
return $self->{$method};
};
}
else
{
my $pack = ref($self);
croak "Can't find method $method via package $self";
}
goto &{$AUTOLOAD};
}
1;
package Linux::Fuser::FileDescriptor;
=head2 Linux::Fuser::FileDescriptor
This is returned by the filedes method of the Linux::Fuser::Procinfo and
contains the information about the file descriptor that the process has the
file open under.
( run in 0.487 second using v1.01-cache-2.11-cpan-e1769b4cff6 )