module Daemonize

def close_io

def close_io
  # Make sure all input/output streams are closed
  # Part I: close all IO objects (except for $stdin/$stdout/$stderr)
  ObjectSpace.each_object(IO) do |io|
    unless [$stdin, $stdout, $stderr].include?(io)
      io.close rescue nil
    end
  end
  # Make sure all input/output streams are closed
  # Part II: close all file decriptors (except for $stdin/$stdout/$stderr)
  3.upto(8192) do |i|
    IO.for_fd(i).close rescue nil
  end
end