writing files to a unix server

I have been told that if my desktop NT is writing a file to a unix server and another server is trying to move the same file at the same time that there will be handshaking problems. My expectation is otherwise. If I am in the process of writing a file, and another process is trying to read the file, I would expect that the file will not be know to other processes until I have completed the write process. Please help with this.
jimdoughertyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
depends on the program which is writing, and the program which is reading, and the protocol used for connecting (mounting).
Usually programs should use exclusive locks while writing a file. The functions to perfom the lock depend on the underlaying mount protocol (NFS, SMB, etc.). Unfortunately there are known problems with exclusive locks (Sun's NFS, SMB, etc.).
Not an easy task if the reading and writing part cannot talk to each other directly :(
0
jlevieCommented:
I think the answer is going to depend on how you're writing the data to the server and possibly what OS the server is running. If you're using a mechanism that can get an exclusive file lock on the file while it's been written, then other access can be blocked until the write is complete. Without an exclusive lock, once you've begun the write the file will exist and there's nothing to prevent another process from trying to read from the file.

In the case of new file creation, Unix creates the file as soon as it's been opened for writing. If you're over-writing an existing file, it simply gets truncated to zero length on the open. In both cases the file name is visible as soon as the open completes.

In most cases Unix will not allow two processes to simultaneously open the file for writing, so that's probably not an issue.
0
jimdoughertyAuthor Commented:
Great and quick response, thanks. I am writing to a unix server. And the other server that may be trying to MOVE the file is also unix. But I am on an NT desktop writing the file. Please tell me how to lock the file while I am writing and then unlock when I am done. According toyour initial response, this should prevent problems.
0
ahoffmannCommented:
> In most cases Unix will not allow two processes to simultaneously open the file
That's not true, just using open() does not prevent multipe processes writing, unfortunately some NFS implementation still fail with even if exclusive locks are used :-(( have a lock at Sun's NFS kernel, especially the cache parameters)

UNIX's lock function is flock(), but keep in mind that it does not work on NFS
0
GP1628Commented:
If possible just write 2 files. data.file then an empty file named go.txt

have the moving routine watch for go.txt, move data.file, delete go.txt, return to watching

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.