I'm working on a piece of code which monitors a directory and performs certain tasks when a new file is created in that directory. I'm using FSSM and my (simplified) code looks like this:
require 'fssm'
class FileWatcher
def initialize
FSSM.monitor('./temp/', '**/*', :directories => true) do
create do |base, relative|
puts "Create called with #{relative}"
end
end
end
end
FileWatcher.new
The file monitoring aspect works well, but my problem is when I halt this script. What happens is the "file_monitor" process remains running. E.g. this is after running and halting the script 3 times:
$ ps aux | grep file_watcher
root 3272 1.0 5.3 9760 6596 pts/0 Tl 00:11 0:02 ruby file_watcher.rb
root 3302 1.5 5.2 9760 6564 pts/0 Tl 00:14 0:02 ruby file_watcher.rb
root 3314 2.2 5.2 9764 6564 pts/0 Sl+ 00:14 0:02 ruby file_watcher.rb
I.e. there are 3 processes still running. So, how to clean up upon exit of the script?