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. Eg 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
Ie there are 3 processes still running. So, how to clean up upon exit of the script?
在父进程中安装一个信号处理程序,该信号处理程序将在信号即将被信号杀死(SIGINT,SIGTERM,SIGQUIT,SIGHUP)时触发,然后依次向子进程(FSSM监视器)发送适当的信号。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.