CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Which process have a file open

 



perl123soumen
New User

Jun 16, 2011, 2:43 AM

Post #1 of 3 (2249 views)
Which process have a file open Can't Post

Hi;

I have used Linux::Fuser for determining the proceeses using a file.

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.

Thus it is not working in higher kernel version.

Pls. suggest any cpan module or perl function to determine processes using a particular file,so that i can wait for the process to finish to work upn the file.


Regards;

soumen.



miller
User

Jun 16, 2011, 10:59 AM

Post #2 of 3 (2241 views)
Re: [perl123soumen] Which process have a file open [In reply to] Can't Post

Don't double post your questions mate. You've already asked this question:

http://perlguru.com/gforum.cgi?post=57266;

- Miller


perl123soumen
New User

Jun 17, 2011, 5:50 AM

Post #3 of 3 (2218 views)
Re: [miller] Which process have a file open [In reply to] Can't Post

I have found a soln.;

use Unix::Lsof;

my $CheckUser=&CheckFile($file,$DirPathPMTA);

sub CheckFile
{

my ($file,$DirPathPMTA)= @_;

my ($output,$error) = lsof(+D,"$DirPathPMTA");


foreach $key (keys %$output)
{
if(( $output->{$key}->{"command name"} eq "ftp") || ( $output->{$key}->{"command name"} eq "vsftpd"))
{

my ($output,$error) = lsof("+p",$output->{$key}->{"process id"});

foreach $key (keys %$output)
{
for my $files ( @{ $output->{$key}{files} } )
{
if ($files->{"file name"}=~m/$file/s)
{

return $files->{"file name"};

}


}
}
}
}

}



This checks for file access through ftp before prcoessing starts.

Waiting foe enhancement of the code.



Soumen

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives