Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

A file revert back to its original contents

by donno20 (Sexton)
on Apr 11, 2003 at 03:29 UTC ( [id://249796]=perlquestion: print w/replies, xml ) Need Help??

donno20 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I was facing a problem like this.

Open a file handler by using the open function and made some changes on its, then close the file handler. Checked the file and it was updated.

let's say there is a second program (or routine) open the same file (for reading only), immediately after the one above, I found out that the file will be reverted back to its original contents.

This problem appear unless I issue sync command with system("sync") in between both of the programs(routines) above.

So what happen behind ? Why should I issued sync ? Isn't it the file was updated and save properly after I close the file handler in the first program ?

  • Comment on A file revert back to its original contents

Replies are listed 'Best First'.
Re: A file revert back to its original contents
by tachyon (Chancellor) on Apr 11, 2003 at 05:26 UTC

    flock is your friend. Or sysopen which is even better as it lets you do an atomic open and LOCK_EX.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: A file revert back to its original contents
by MarkM (Curate) on Apr 11, 2003 at 04:06 UTC

    Is your file system mounted over the network? The symptoms you describe only make sense for a network mounted file system.

      Hi Mark,
      The code do a mounting before open the file handle and unmount after close it.
      However it was not across network, just mount/unmount on local disk partition.

        This could happen if one of the scripts was mounting the filesystem correctly and the other wasn't, you have one version of the file in the directory the filesystem gets mounted on, and one on the filesystem itself, so if the filesystem is mounted, you get that one, otherwise you get the one that is normally 'underneath' the mounted filesystem. Umount it and look in the place where it was mounted to see if the file the other script is getting is there...


        We're not surrounded, we're in a target-rich environment!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://249796]
Approved by dorko
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-16 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found