Hello,
The following doesn't work as I expected and would like <g>:
#!/usr/bin/ruby
if 'exec' == ARGV[0]
File.new($0).flock(File::LOCK_EX)
puts "Locked #{$0} at #{Time.now}"
exec($0, 'sleep')
elsif 'sleep' == ARGV[0]
sleep(10)
File.new($0).flock(File::LOCK_UN)
puts "Unlocked #{$0} at #{Time.now}"
sleep(10)
exit
else
File.new($0).flock(File::LOCK_SH )
puts "Got shared lock at #{Time.now}"
end
# end-of-program
If I call this /tmp/trylock.rb, and chmod a+x it, and I type in:
/tmp/trylock.rb exec &
/tmp/trylock.rb
I get something like:
Locked /tmp/trylock.rb at Wed Feb 16 14:26:49 CET 2005
Unlocked /tmp/trylock.rb at Wed Feb 16 14:26:59 CET 2005
Got shared lock at Wed Feb 16 14:27:09 CET 2005
Strace shows that no system-call to flock(n, LOCK_UN) is ever made.
Is there something I missed here ?
Thanks in advance for any hints,
Cheers,
Han Holl