Curious situation with unlink() and open()
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Mon Apr 30 04:59:15 UTC 2012
To C experts:
unlink(2) takes path[] instead of 'fd'. How do people deal with the
following situation?
1. Same file is open()ed in 2 different processes (same program, but
different instances), so that you have fd1 and fd2.
2. Both fd1 and fd2 try for write-lock. Since fd1 started first, it
gets the write-lock, while fd2 waits until fd1 is closed. That's
fine.
3. You do some I/O with fd1. Then, you unlink() the original file,
and close(fd1). Even though the file may be gone from sight, fd2 is
still active, so inode2 is still there.
4. Now that fd1 is closed, fd2 gets the write-lock. You do some I/O
with fd2, and close(fd2).
5. Since all reference to the original file is gone, the file is
permanantly gone, along with all I/O done with fd2. Bummer!
How do you keep what you did with fd2?
--
William
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list