Solved

unlink file succeed and no content for the file but the file is still  there

Posted on 2014-01-06
7
278 Views
Last Modified: 2014-01-21
I used Perl to detect a directory. If there is a new file coming, I copy this file to dest directory and then unlink this file from the src directory. Most cases are good. But in some rare cases, the file is still left in the src directory. Actually the left files had been copied to dest directory successfully. The left files are zero in size. This rare case usually happens in integral point clock. Does anyone has this problem before?
0
Comment
Question by:c11v11
7 Comments
 
LVL 8

Expert Comment

by:Surrano
ID: 39759440
There's probably some process holding the file open.
What filesystem(s) are we talking about?
Is the allocated space released in such occasions or still occupied by a "phantom" version of the file?

You may try using "lsof" or "lsof -X" to find what process keeps the file open, but if it's a momentary thing then maybe you'll never catch it. Even if you catch it, you have to understand how to alter the behaviour either the process in question or your script.

As a workaround, though, if it happens only between HH:00:00.000000 and HH:00:00.999999 then check the time before the unlink and if it falls in this interval then sleep one second. If you post a snippet of the script that does the unlink, I'll try to come up with a syntactically correct solution.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39759520
Is your directory NFS mounted (or some other remote file-system method)?  I've seen NFS do weird things (most often seemingly when it thinks a file is in use).
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39760397
How are you checking that the file is complete, ie: not being written to before copying?
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 8

Expert Comment

by:Surrano
ID: 39761370
Tintin's right; if it is not well-defined uncomfortable events may occur. If you can influence the sw creating the files, do something like create file "somefile.someuniqueid.tmp" and once complete, i.e. right after closing the file, rename it to "somefile.someuniqueid". Moving those files around should be piece of cake.

If you can't influence the software and you don't know its exact behaviour I think the best you can do is to check whether file is still open. Also, consider moving instead of copy+unlink if it makes sense in your use case.
0
 

Author Comment

by:c11v11
ID: 39774307
We are using NFS. The are 160 client  writing to this NFS share at the same time. I asked the developer if there is tmp file created when the clients wrote to the NFS share.  The developer said yes.  But I did not notice this. ( the file is very small, maybe it is not very easy to see this) This only happened on the integral point clock. That is very strange.Why does this only happen on integral point clock??
0
 
LVL 8

Accepted Solution

by:
Surrano earned 50 total points
ID: 39775855
Probably because a cron job runs at the same time, affecting either the files in question or the nfs share itself.
0
 

Author Closing Comment

by:c11v11
ID: 39798793
This is the problem. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question