lock file between two process
I need to lock a file, which will be accessed by a Java program (multi-thread). The content of the file is written by a C programme. I try the file lock (similar to the book - Advanced Linux Programming). It doesn't work because when reading the file and paring it, it returned with a error, saying no content inside the file (but `cat file_name` I can see the content exactly there). How can I lock a file that can prevent other processes (the Java programme) access the file before the writing process (the C programme) finishes its jobs? Or what to do to prevent such problem occurs?
The code snippet of locking file in C I write is as follow: Code:
... |
Most file locking is "advisory locking", in which processes must cooperate with each other in order for the locking to take effect. If you're trying to lock out from a file any arbitrary unknown code, advisory locking won't work.
No, you want "mandatory locking". See: http://linux-security.cn/ebooks/ulk3...12-SECT-7.html For words from the Linux horse's mouth, see: http://www.in-ulm.de/~mascheck/vario.../mandatory.txt Hope this helps. |
man select
|
All times are GMT -5. The time now is 06:00 PM. |