Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ensuring a complete file read on Solaris

Status
Not open for further replies.

Sudmill

Programmer
Apr 20, 2001
65
GB
Hi,

Sorry if this is a remarkably simple question, but I am writing a process to run under cron to monitor for files and process them. I havent written C on Unix before but I understand that when a file is being written, as there is no locking I could in effect process a file that hasnt been copmpletely written.

Is there any programmable solution to check to see if the file is completely copied over. The only solution I can think of is to conintually poll the file on it exists and check to see if the file size stops growing, at which point I can assume that the file has been completely written ??

Am I write in thinking that under NT I wouldnt be able to get a handle on the file if another process was writing to it?

Once again sorry if this is a really simple qu.

John.


 
Probably the easiest way to do it is to have both processes use flock() <sys/file.h> on the file. See man flock

If you don't have control over how the other process handles the file, no easy solution comes to mind. Perhaps you could arrange to have the cron job run at a time when you know another process isn't writing to the file. Without knowing more about your particular situation, it's hard to say without speculating a lot.

Russ
bobbitts@hotmail.com
 
Thanks for your reply.

As it happens tHe other process is a windows process on a NFS partition therefore I have no control over that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top