RosettaCodeData/Task/Determine-if-only-one-instance-is-running/Ruby/determine-if-only-one-instance-is-running.rb
2023-07-01 13:44:08 -04: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__