Skip to content

Instantly share code, notes, and snippets.

@eric
Created November 25, 2009 23:36
Show Gist options
  • Select an option

  • Save eric/243094 to your computer and use it in GitHub Desktop.

Select an option

Save eric/243094 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def fork_test(command)
pid = Kernel.fork do
exec command
end
puts "parent sees pid: #{pid}"
Process.waitpid(pid)
end
puts "Only single quotes:"
fork_test(%{ruby -e 'puts Process.pid'})
puts "With double quotes:"
fork_test(%{ruby -e "puts Process.pid"})
puts "With braces quotes:"
fork_test(%{ruby -e 'puts "#{Process.pid}"'})
> ruby exec-test.rb
Only single quotes:
parent sees pid: 26766
26766
With double quotes:
parent sees pid: 26767
26767
With braces quotes:
parent sees pid: 26768
26765
> ruby -v
ruby 1.8.6 (2008-08-08 patchlevel 286) [i686-linux]
> ruby exec-test.rb
Only single quotes:
parent sees pid: 18425
18425
With double quotes:
parent sees pid: 18426
18426
With braces quotes:
parent sees pid: 18427
18424
> ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2009.10
> ruby exec-test.rb
Only single quotes:
parent sees pid: 33453
33453
With double quotes:
parent sees pid: 33454
33454
With braces quotes:
parent sees pid: 33455
33452
> ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment