Filehandling Problem

Hey!

I have a multiple process ruby application and i want to do process
flagging over the filesystem (similar to apaches alive flag).

I have a process that runs a loop creates a file and sleeps a while:

loop do

f1 = File.new(Dir.getwd+"/process1",“w”).flock(File::LOCK_UN) do |f|
f.puts “process1”
end

sleep 60

end

In my root process i want to be able to delete this file, even when the
other process is running:

require ‘win32/process’

puts “Starting Process 1”

process1 = Process.create(:app_name => “ruby process1.rb”)

#puts “Starting Process 2”

#process2 = Process.create(:app_name => “ruby process2.rb”)

puts “started”

loop do

File.delete(Dir.getwd+"/process1")

sleep 10

end

I get a “Permission denied” error, even if i set the option
flock(File::LOCK_UN) how can i remove the file lock?

greez ck

Christian K. wrote:
Forgot to close the File…

…damn! :wink:

loop do

f1 = File.new(Dir.getwd+"/process1",“w”).flock(File::LOCK_UN) do |f|
f.puts “process1”
end

sleep 60

end