NAME

Linux::Fuser - Determine which processes have a file open

SYNOPSIS

use Linux::Fuser;

my $fuser = Linux::Fuser->new();

my @procs = $fuser->fuser('foo');

foreach my $proc ( @procs )
{
  print $proc->pid(),"\t", $proc->user(),"\n",@{$proc->cmd()},"\n";
}

DESCRIPTION

This module provides information similar to the Unix command 'fuser' about which processes have a particular file open. The way that this works is highly unlikely to work on any other OS other than Linux and even then it may not work on other than 2.2.* kernels. Some features may not work correctly on kernel versions older than 2.6.22

It should also be borne in mind that this may not produce entirely accurate results unless you are running the program as the Superuser as the module will require access to files in /proc that may only be readable by their owner.

METHODS

new

The constructor of the object. It takes no arguments and returns a blessed reference suitable for calling the methods on.

fuser SCALAR $file

Given the name of a file it will return a list of Linux::Fuser::Procinfo objects, one for each process that has the file open - this will be the empty list if no processes have the file open or undef if the file doesnt exist.

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.

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 ).

pid

The process id of the process that has the file open.

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.

filedes

A Linux::Fuser::FileDescriptor object that has details of the file as the process has it opened - see below.

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.

The information which this is based on is only available from Linux Kernel version 2.6.22 onwards so will not be available on earlier kernels (except the 'fd'.)

It has the following methods (though future versions of the Linux Kernel may provide different or fuller information via /proc/$pid/fdinfo):

fd

The file descriptor that this file is opened under - this will be unique within a process (if a file is opened more than once by a process) but not within the system.

flags

The flags with which the file was opened (by open or creat) as a long integer.

pos

The location (in bytes) of the file pointer within the file.

EXPORT

None.

AUTHOR

Jonathan Stowe, <jns@gellyfish.co.uk>

SUPPORT

Patches are always welcome against the latest code at https://github.com/jonathanstowe/Linux-Fuser

COPYRIGHT AND LICENSE

Please see the README file in the source distribution.

SEE ALSO

perl. proc(5)