From: ts Date: 2003-07-26T00:40:32+09:00 Subject: Re: Confused about locking a file via file.flock(File::LOCK_EX) >>>>> "L" == Ludwigi Beethoven writes: L> what I thought it will do. To test it, I wrote a L> simple ruby piece of code that, first locks the file, L> second spin-loop forever while I open another window L> and vi the "locked" file. Well, I am able to vi and L> change the file that is supposed to be locked. Well, to understand the problem svg% cat b.rb #!/usr/bin/ruby f = File.new("aa", "w") f.flock(File::LOCK_EX) puts "file locked #{Process.pid}" fork do g = File.new("aa", "w") if !g.flock(File::LOCK_SH|File::LOCK_NB) puts "error : file locked #{Process.pid}" end end Process.wait fork do g = File.new("aa", "w") g.puts "aa" end Process.wait svg% svg% cat aa cat: aa: No such file or directory svg% svg% b.rb file locked 25340 error : file locked 25341 svg% svg% cat aa aa svg% a lock work *only* if the process try to acquire a lock before writing in the file. In my example, the first fork test if the file is locked and give an error if it can't have the lock. The second fork, don't test and write directly in the file (it bypass the lock) In your case, vi do like my second fork : it don't try to acquire a lock and write in the file Guy Decoux