views:

68

answers:

2

The situation I'm in is this - there's a process that's writing to a file, sometimes the file is rather large say 400 - 500MB. I need to know when it's done writing. How can I determine this? If I look in the directory I'll see it there but it might not be done being written. Plus this needs to be done remotely - as in on the same internal LAN but not on the same computer and typically the process that wants to know when the file writing is done is running on a Linux box with a the process that's writing the file and the file itself on a windows box. No samba isn't an option. xmlrpc communication to a service on that windows box is an option as well as using snmp to check if that's viable.

Ideally

  • Works on either Linux or Windows - meaning the solution is OS independent.
  • Works for any type of file.

Good enough:

  • Works just on windows but can be done through some library or whatever that can be accessed with Python.
  • Works only for PDF files.

Current best idea is to periodically open the file in question from some process on the windows box and look at the last bytes checking for the PDF end tag and accounting for the eol differences because the file may have been created on Linux or Windows.

+1  A: 

There are probably many approaches you can take. I would try to open the file with write access. If that succeeds then no-one else is writing to that file.

Build a web service around this concept if you don't have direct access to the file between machines.

Muhimbi
Yep we've been thinking about doing that or try to move / rename the file to see if it succeeds once we see it's present in the directory. As for race conditions well I don't see any here because we would only try it once we see the file (meaning the writing process already has opened it for write and may or may not have closed it.)
Khorkrak
A: 

I ended up resolving it for our situation. As it turns out the process that was writing the files out had them opened exclusively so all we had to do was try opening them for read access - when denied they were in use.

Khorkrak