# Filehandling Problem

**URL:** <https://www.ruby-forum.com/t/filehandling-problem/130082>\
**Category:** Ruby\
**Created:** [February 25, 2008, 9:23am UTC](https://www.ruby-forum.com/t/filehandling-problem/130082 "2008-02-25T09:23:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [February 25, 2008, 9:23am UTC](https://www.ruby-forum.com/t/filehandling-problem/130082/1 "2008-02-25T09:23:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [February 25, 2008, 9:57am UTC](https://www.ruby-forum.com/t/filehandling-problem/130082/2 "2008-02-25T09:57:23Z")

</div>

Christian K. 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
