checking if a file is in use

checking if a file is in use

am 02.11.2010 19:49:04 von perl_haxor 123

--001517576c0005365204941661e0
Content-Type: text/plain; charset=ISO-8859-1

Hi All,

I have a directory in which i have multiple files, i have to read
each one of them and parse the data......but there could be some files which
are in use by some other program, how can i find which files are in use by
other program in perl?.......any suggestions would be really helpful.



Thanks,
Monnappa

--001517576c0005365204941661e0--

Re: checking if a file is in use

am 02.11.2010 20:32:52 von Jim Gibson

On 11/2/10 Tue Nov 2, 2010 11:49 AM, "perl_haxor 123"
scribbled:

> Hi All,
>
> I have a directory in which i have multiple files, i have to read
> each one of them and parse the data......but there could be some files which
> are in use by some other program, how can i find which files are in use by
> other program in perl?.......any suggestions would be really helpful.

What operating system are you using? Does it provide a way to determine
which files are in use?



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: checking if a file is in use

am 02.11.2010 20:40:07 von Shlomi Fish

Hi Monnappa,

On Tuesday 02 November 2010 20:49:04 perl_haxor 123 wrote:
> Hi All,
>
> I have a directory in which i have multiple files, i have to read
> each one of them and parse the data......but there could be some files
> which are in use by some other program, how can i find which files are in
> use by other program in perl?.......any suggestions would be really
> helpful.
>

I don't know about Windows, but on UNIX you can use lsof:

http://en.wikipedia.org/wiki/Lsof

This page says that http://en.wikipedia.org/wiki/Process_Explorer is the
Windows equivalent.

However, you should rethink your strategy. If you want well-behaving processes
not to step on each others' toes you can use file locking for that.

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

She's a hot chick. But she smokes.
She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Fwd: Re: checking if a file is in use

am 02.11.2010 21:01:59 von Shawn Wilson

--000e0cd47c48c3f412049417654f
Content-Type: text/plain; charset=ISO-8859-1

---------- Forwarded message ----------
From: "shawn wilson"
Date: Nov 2, 2010 3:12 PM
Subject: Re: checking if a file is in use
To: "perl_haxor 123"

perlmonks has a nice article on file locks in general that might be useful
to you. i assume what you want to do is lock the file or die.
http://www.perlmonks.org/?node_id=7058


On Tue, Nov 2, 2010 at 2:49 PM, perl_haxor 123 wrote:

> Hi All,
>
> I have a directory in which i have multiple files, i have to read
> each one of them and parse the data......but there could be some files
> which
> are in use by some other program, how can i find which files are in use by
> other program in perl?.......any suggestions would be really helpful.
>
>
>
> Thanks,
> Monnappa
>

--000e0cd47c48c3f412049417654f--

Re: Re: checking if a file is in use

am 02.11.2010 22:46:22 von perl_haxor 123

--000e0cd6a9c01b0965049418dbaf
Content-Type: text/plain; charset=ISO-8859-1

Hi All,

Thanks a lot for the suggestion, It looks like flock is used if my
perl script want to lock a file, In this case the perl script would be
copying files from one directory to an another one, but some process (let
say xyz process) might be using these files, in that case i don't want to
copy the file used by another process (xyz process).......please let me know
how can i find out if file is locked by the process (xyz)?......can flock
be used for that....and also the system is linux system.


Thanks,
Monnappa

On Wed, Nov 3, 2010 at 1:31 AM, shawn wilson wrote:

> ---------- Forwarded message ----------
> From: "shawn wilson"
> Date: Nov 2, 2010 3:12 PM
> Subject: Re: checking if a file is in use
> To: "perl_haxor 123"
>
> perlmonks has a nice article on file locks in general that might be useful
> to you. i assume what you want to do is lock the file or die.
> http://www.perlmonks.org/?node_id=7058
>
>
> On Tue, Nov 2, 2010 at 2:49 PM, perl_haxor 123
> wrote:
>
> > Hi All,
> >
> > I have a directory in which i have multiple files, i have to
> read
> > each one of them and parse the data......but there could be some files
> > which
> > are in use by some other program, how can i find which files are in use
> by
> > other program in perl?.......any suggestions would be really helpful.
> >
> >
> >
> > Thanks,
> > Monnappa
> >
>

--000e0cd6a9c01b0965049418dbaf--