From: Matt Armstrong Date: 2002-12-15T04:46:47+09:00 Subject: Re: Ruby BUG when using PStore and fork Jeremy Henty writes: > In article <873cp128ap.fsf@squeaker.lickey.com>, Matt Armstrong wrote: >> ahoward writes: >> >>> i have gotten around this problem by spawning another process using >>> the unix at command with a time of 'now' >> >> system("thecommand &") > > This doesn't solve the problem, which was that the child process > inherits a lock on the pstore archive. After experimenting, there is a way to close the PStore file in the child process in ruby 1.7. This program demonstrates it. In a PStore transaction, it forks a child that just loops 5 times printing a message, sleeping between. Without the call to close_extra_files, the child blocks the parent's 2nd attempt to start a transaction. With the call, it ends up closing the PStore file it inherits from its parent and allows the parent to open the PStore file again. Unfortunately, I don't know a way to close file descriptors 3-1024 in ruby 1.6. require 'pstore' store = PStore.new('pstore.test') def close_extra_files 3.upto(1024) { |i| begin File.open(i).close rescue Errno::EINVAL end } end store.transaction { |ps| puts "parent forking child" fork { close_extra_files 5.times { sleep(1) puts "child is alive" } exit! } } puts "parent trying for second transaction" store.transaction { |ps| puts "parent got second transaction" } Process.wait