[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

writing files to a unix server

Posted on 2000-02-10
5
Medium Priority
?
346 Views
Last Modified: 2010-04-21
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.
0
Comment
Question by:jimdougherty
5 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2507587
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
 
LVL 40

Expert Comment

by:jlevie
ID: 2507627
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
 

Author Comment

by:jimdougherty
ID: 2507688
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2507848
> 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
 
LVL 2

Accepted Solution

by:
GP1628 earned 150 total points
ID: 2580921
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

591 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