?
Solved

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

Posted on 2014-01-06
7
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

752 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