Well as far as I know there is no direct function or way to find processes using a file... so I wrote this, it could be bad code I dunno feel free to tell me, and also btw it should really only work on linux (or any other os that stores files open in /proc/pid/fd/file desc)
use Linux::Fuser;
Was this ugly mess from the year 2000:
package File::Fuser;
use strict;
use vars qw( @ISA @EXPORT );
use File::Spec;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(fuser);
sub fuser {
my($file) = File::Spec->rel2abs($_[0]);
my($f,@pids);
foreach(glob("/proc/*")) {
if ($_ =~ /^\/proc\/\d+$/) {
foreach $f(glob("$_/fd/*")) {
if ((reverse(File::Spec->splitpath($f)))[0] > 3 && -l
+$f) {
if (readlink($f) eq $file) {
push(@pids,(reverse(File::Spec->splitpath($_))
+)[0]);
}
}
}
}
}
return((@pids)? @pids : -1);
}
1;