[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Filehandling Problem

Christian Kerth

2/25/2008 8:24:00 AM

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
--
Posted via http://www.ruby-....

1 Answer

Christian Kerth

2/25/2008 8:57:00 AM

0

Christian Kerth wrote:
Forgot to close the File...

....damn! ;-)


> loop do
>
> f1 = File.new(Dir.getwd+"/process1","w").flock(File::LOCK_UN) do |f|
> f.puts "process1"
> end
>
> sleep 60
>
> end
--
Posted via http://www.ruby-....