From: Walton Hoops Date: 2010-02-22T08:58:36+09:00 Subject: Re: Difference between system() versus exec Kernel methods On 2/21/2010 4:38 PM, Alex DeCaria wrote: > That's well and good. I've already read the documentation. But, based > on the documentation I would expect to see only a single process running > after calling the exec method. So, why are there two? > > I'm obviously not reading the documentation correctly, and that's why I > need someone who can explain it. > > --Alex > This line from the docs explains it: In MSDOS environments, the command is executed in a subshell; otherwise, one of the +exec(2)+ system calls is used, so the running command may inherit some of the environment of the original program (including open file descriptors). The trick is, exec uses the underlying OSes exec. In Linux, that does as you expect and simply replaces the running process in memory. In Windows however, there is no equivalent to the Linux exec, so we pretend. Ruby execs the specified command (via the Windows version of exec which starts a second process) and exits once it's done, thus there are two processes. To demonstrate this try running the following: exec "echo boo" puts "I hope I don't get here" Notice that the puts statement never gets run.