1 同样都是创建子进程
Process.fork{ } 是非阻塞的执行,创建的子进程与父进程并发运行,需要使用Process.wait或者Process.detach来防止产生zommbie process
Kernel#exec, Kernel#system and Backticks(%x)阻塞的执行,调用者将等待被调用的返回
2 Kernel#exec, Kernel#system and Backticks(%x) 区别
Kernel#exec 用新创建的子进程取代原来的进程
exec('ls ~')
# Nothing after this command is executed
Backticks or %x shortcut 创建子进程,子进程返回运行的结果
`ls ~`
=> "Applications\nDesktop\nDocuments"
%x(ls ~)
=> "Applications\nDesktop\nDocuments"
Kernel#system 创建子进程,子进程返回true(command run successfully),false(unsuccessful)或者 nil (command execution failed):
system('ls ~')
=> true
Resource
Process.fork http://www.ruby-doc.org/core-2.0/Process.html#method-c-fork
Kernel#exec, Kernel#system and Backticks(%x)区别详解 http://rubyquicktips.com/post/5862861056/execute-shell-commands