Created
November 25, 2009 23:36
-
-
Save eric/243094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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}"'}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > 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