puts "Process #{Process.pid} started"
return_value = fork
puts "Process #{Process.pid} returned #{return_value}"
puts "Process #{Process.pid} exited"
上面的 ruby 代码将此输出打印到 STDOUT
Process 6644 started
Process 6644 returned 6645
Process 6644 exited
Process 6645 returned
Process 6645 exited
父进程执行fork
时,返回子进程的pid。当子进程调用fork
为什么它返回nil
时,这不应该是递归调用吗?就像.. child 也分叉了另一个子进程.. 而那个子进程分叉了另一个进程..等等,我在这里遗漏了什么吗?