How to checking a file that writing is complete?

N

news.hinet.net

I must mv a logfile to other directory that generate by another program.
Will I got incomplete file if move a file that writing is not complete ?

one process proc1
system("mv /a/c/logfile /a/b/logfile");

and the other process proc2
open(handle,"/a/b/logfile")

ps: os->unix or linux
 
J

Joe Smith

news.hinet.net said:
I must mv a logfile to other directory that generate by another program.
Will I got incomplete file if move a file that writing is not complete ?

It depends on whether the original directory and the destination directory
are on the same file system. If yes, 'mv' does a rename without changing
the inode; open file handles are still valid. If no, 'mv' does a copy
and delete; you may end up with a large file that is still open but has
no name.

As to checking whether a file is still open for writing, perl can't
do it if the OS + file-system don't support that functionality.
-Joe
 
P

Paul Robson

news.hinet.net said:
one process proc1
system("mv /a/c/logfile /a/b/logfile");

and the other process proc2
open(handle,"/a/b/logfile")

ps: os->unix or linux

I presume these are running in parallel.

Aren't there semaphores in Perl ?
 
N

news.hinet.net

What is the definition of the original directory and the destination
directory
are on the same file system??

The meaning is the same partition , the same filesystem type(ex. NTFS
<->NTFS) or
the same HardDisk?

Sorry! My english is very poor!
 
M

Michele Dondi

What is the definition of the original directory and the destination
directory are on the same file system??

It's that they must be on the same file system!!
;-)
The meaning is the same partition , the same filesystem type(ex. NTFS
<->NTFS) or the same HardDisk?

Amongst these choices: same partition. More generally: same... ehm!
filesystem. Sorry for the tautology...


HTH,
Michele
 
B

Ben Morrow

[quoting fixed. Don't top-post]

Quoth "news.hinet.net said:
What is the definition of the original directory and the destination
directory
are on the same file system??

The meaning is the same partition , the same filesystem type(ex. NTFS
<->NTFS) or
the same HardDisk?

Err... are you talking windows or unix here?
Windows (AFAIK) doesn't support close-behind (where a file can be
renamed without processes holding it open knowing), so you'll have to
tell the writer to stop and restart around the move.

Under Unix you can get a list of filesystems with mount(1): any two
directories that are under the same entry in mount's output are on
the same filesystem. So, if mount says

/dev/hda1 on / type reiserfs (rw,noatime)
/dev/hda2 on /usr type reiserfs (rw,noatime)
/dev/hda3 on /usr/local type reiserfs (rw,noatime)

then /, /lib, etc. are on one filesystem; /usr, /usr/lib, /usr/lib/perl5
etc. are on another and /usr/local, /usr/local/bin etc. are on a third.

You can check which filesystem a file (or directory) is on with stat:
the first member ($st->dev if you use File::stat, which I'd recommend)
gives you the device (filesystem) number, so two files are on the same
fs iff stat returns the same first member for both. Be aware that 'fake'
filesystems (such as Linux' usbfs (/proc/bus/usb) and tmpfs (often used
for /dev and /dev/shm)) may return 'undef' for this member, so be
careful to catch this.
Sorry! My english is very poor!

That's fine: don't worry about it :).

Ben
 
M

Michele Dondi

fs iff stat returns the same first member for both. Be aware that 'fake'
filesystems (such as Linux' usbfs (/proc/bus/usb) and tmpfs (often used
for /dev and /dev/shm)) may return 'undef' for this member, so be

<OT>
I think that nowadays it is common for /dev to be on devfs, which btw
doesn't contradict the key point you're addressing, since it is just
as 'fake'.
</OT>


Michele
 
B

Ben Morrow

Quoth Michele Dondi said:
<OT>
I think that nowadays it is common for /dev to be on devfs, which btw
doesn't contradict the key point you're addressing, since it is just
as 'fake'.

It was. As of 2.6 devfs is deprecated and the alternative is udev, which
is a tmpfs with device nodes created by a userspace daemon.

devfs, I believe, *does* have a device number (as does /proc); tmpfs
does not. :)

Ben
 
M

Michele Dondi

It was. As of 2.6 devfs is deprecated and the alternative is udev, which
is a tmpfs with device nodes created by a userspace daemon.

I know (2.6.8.1 here). Funny thing is that in 2.6 devfs is deemed
deprecated and udev experimental!


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top