From: Eric Christopherson Date: 2010-02-22T09:15:44+09:00 Subject: Re: Difference between system() versus exec Kernel methods On Sun, Feb 21, 2010 at 5:58 PM, Walton Hoops wrote: > 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. Sounds like the doc should be updated to mention Windows. > > 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.