flock doesn't work with exec'd files ?

H

Han Holl

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top