From: Yusuke ENDOH Date: 2010-11-15T12:29:14+09:00 Subject: [ruby-core:33186] Re: [Ruby 1.9-Feature#4046][Open] Saving C's **argv and cwd allows Ruby programs to reliably restart themselves Hi, 2010/11/12 Rocky Bernstein : > In a debugger often one gets to a state where one just wants to restart everything exactly the way the program was previously invoked. exec(3) allows us to fake argv[0]. Unfortunately, there is no truely reliable way to re-invoke process, at least, in Unix. $ cat test.rb # # test.rb # Dir.chdir RubyVM::OS_STARTUP_DIR puts "***" puts "*** exec: %p" % RubyVM::OS_ARGV.join(" ") puts "***" exec(*RubyVM::OS_ARGV) # http://cr.yp.to/ucspi-tcp/argv0.html $ argv0 ./ruby cat test.rb *** *** exec: "cat test.rb" *** # # test.rb # Dir.chdir RubyVM::OS_STARTUP_DIR puts "***" puts "*** exec: %p" % RubyVM::OS_ARGV.join(" ") puts "***" exec(*RubyVM::OS_ARGV) # You can do the same with perl, ruby, etc. $ perl -e 'exec { "./ruby" } ("cat", "test.rb")' $ ruby -e 'exec(["./ruby", "cat"], "test.rb")' -- Yusuke Endoh