I ran into a bug (feature?) in Tempfile/fork interaction. Specifically, my
Tempfile gets deleted once a fork exits. Presumably, the finalizer is being
called for the child process which is what actually does the deletion. Is
this how it's "supposed" to work?

Below is a short example to illustrate.

Thanks,

-M


#!/usr/bin/ruby
require 'tempfile'

tmp_file = Tempfile.new("tmp")
tmp_file.print "This is a tmp_file\n"
tmp_file.close(false)
puts "tmp_file exists" if File.exists?(tmp_file.path)

fork {
  puts "tmp_file exists at begining of fork" if File.exists?(tmp_file.path)
  sleep 2
  puts "fork exits"
}

1.upto(5) { |x|
  if File.exists?(tmp_file.path)
    puts "tmp_file exists time #{x}" 
  else
    puts "tmp_file doesn't exist at time #{x}"
  end
  sleep 1
}

> ruby --version
ruby 1.6.2 (2001-01-15) [i486-linux]

> ruby test.rb
tmp_file exists
tmp_file exists time 1
tmp_file exists at begining of fork
tmp_file exists time 2
tmp_file exists time 3
fork exits
tmp_file doesn't exist at time 4
tmp_file doesn't exist at time 5