What is the cause of file truncation?
I have a program that gets called from the front end of my application. Actually it creates some temporary files and uses them and deletes them at last. But sometimes, say once in 6 times, some of these temporary files are getting truncated in the middle and because of this my program is behaving irregularly. My application runs on AIX.
I am not sure -
1) whether some other process is truncating the files, or
2) My program itself is writing the files incompletely.
If I restart the same operation again, I am able to proceede correctly. This kind of trucation of files is happening only some times, say once in 6 times.
I want to monitor these temporary files from creation to the deletion - like what processes are writing to them, using them, truncating them etc.
Can you please tell me, is there a way to do this task? Or, any other better way of solving this problem is possible?
I am not sure if this would help.
Did you try strace ? Read the man pages. It outputs all the system calls by a process. strace is usually for the whole application. In your case it would be the program.
Make sure you call fflush() after every write to your temp files.
This sounds like a program design issue more than a problem with the filesystem.
Are you checking return codes on ALL your file calls?
If you are working on a busy disk where apps create a lot of temp files (like /var/tmp), it is possible for write() not complete successfully because of transient disk full errors. Since this only happens once in a while, this must be the case.
Also consider defining TMPDIR to point to a filesystem with lots of free space or with low disk contention.
If you don't check return codes, the program runs merrily on, regardless of disk free space. I've seen your problem exactly as you describe it under these cricumstances.
I have observed this on one of our systems too. I tried to simulate this using the following programs:
fop.c - uses fopen and fwrite
This may have something to do with the buffering that is done when 'fwrite'ing - this causes the 'fwrite' to return success, even though 'write' fails.
But this does not really sound right.. could any one shed light on this?
blowtorch, your problem is due to buffering as you suspect. You could use setvbuf() to unbuffer. Or you could check the return code from fclose() which will detect the problem. Ideally, you check the return code from close() as well... although no one ever does. With an NFS mounted filesystem, close() could be the syscall that detects a full filesystem.
|All times are GMT -4. The time now is 06:56 PM.|
Powered by: vBulletin,
Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2013. All Rights Reserved.
Forum Operations by The UNIX and Linux Forums