Difference between system() versus exec Kernel methods

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

···

--
Posted via http://www.ruby-forum.com/.

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.

···

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

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.

···

On Sun, Feb 21, 2010 at 5:58 PM, Walton Hoops <walton@vyper.hopto.org> wrote:

On 2/21/2010 4:38 PM, Alex DeCaria wrote:

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.

Thanks! That makes it clearer. --Alex

···

--
Posted via http://www.ruby-forum.com/.