How to checking a file that writing is complete?

Discussion in 'Perl Misc' started by news.hinet.net, Oct 17, 2004.

  1. 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
     
    news.hinet.net, Oct 17, 2004
    #1
    1. Advertising

  2. news.hinet.net

    Joe Smith Guest

    news.hinet.net wrote:

    > 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
     
    Joe Smith, Oct 17, 2004
    #2
    1. Advertising

  3. news.hinet.net

    Paul Robson Guest

    news.hinet.net wrote:

    > 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 ?
     
    Paul Robson, Oct 17, 2004
    #3
  4. 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!

    "Joe Smith" <> ??? news:bTpcd.143051$He1.29216@attbi_s01
    ???...
    > news.hinet.net wrote:
    >
    > > 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
     
    news.hinet.net, Oct 17, 2004
    #4
  5. On Sun, 17 Oct 2004 17:30:13 +0800, "news.hinet.net"
    <> wrote:

    >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
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Oct 17, 2004
    #5
  6. news.hinet.net

    Ben Morrow Guest

    [quoting fixed. Don't top-post]

    Quoth "news.hinet.net" <>:
    > "Joe Smith" <> ??? news:bTpcd.143051$He1.29216@attbi_s01
    > ???...
    > > news.hinet.net wrote:
    > >
    > > > 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.

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

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    /Alcestis/) [ flame, and falls out of sight. ]
     
    Ben Morrow, Oct 18, 2004
    #6
  7. On Mon, 18 Oct 2004 00:44:23 +0100, Ben Morrow <>
    wrote:

    >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
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Oct 18, 2004
    #7
  8. news.hinet.net

    Ben Morrow Guest

    Quoth Michele Dondi <>:
    > On Mon, 18 Oct 2004 00:44:23 +0100, Ben Morrow <>
    > wrote:
    >
    > >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'.


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

    > </OT>


    Ben

    --
    'Deserve [death]? I daresay he did. Many live that deserve death. And some die
    that deserve life. Can you give it to them? Then do not be too eager to deal
    out death in judgement. For even the very wise cannot see all ends.'
     
    Ben Morrow, Oct 19, 2004
    #8
  9. On Tue, 19 Oct 2004 18:22:37 +0100, Ben Morrow <>
    wrote:

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


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


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, Oct 21, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,437
    HNguyen
    Dec 21, 2004
  2. eastcoastguyz
    Replies:
    10
    Views:
    525
    Roland Pibinger
    Dec 14, 2006
  3. Ralf Ziller

    RenderControl not writing complete markup

    Ralf Ziller, Apr 11, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    464
    Ralf Ziller
    Apr 11, 2007
  4. pereges
    Replies:
    8
    Views:
    342
    Flash Gordon
    Jul 22, 2008
  5. Yashesh Bhatia
    Replies:
    5
    Views:
    104
Loading...

Share This Page