RosettaCodeData/Task/Determine-if-only-one-instance-is-running/Ruby/determine-if-only-one-instance-is-running.rb
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

15 lines
232 B
Ruby

def main
puts "first instance"
sleep 20
puts :done
end
if $0 == __FILE__
if File.new(__FILE__).flock(File::LOCK_EX | File::LOCK_NB)
main
else
raise "another instance of this program is running"
end
end
__END__