The following test case illustrates an unexpected behaviour of of Ruby's Kernel#exec
call caused by platform differences between OS X and Linux.
In both tests, a program is spawned that simply prints all the process IDs of its ancestors. From this list, the list of the ancestors of the test process is substracted, so the list only contains ancestors added by the exec
invocation.
In the first test, the comand line /path/to/program
is Kernel#exec
'd. This works on both platforms. However, the second test tries to exec the command line '/path/to/program'
(note the quotes). This leads to a platform difference: while on OS X, just one new ancestor is created, Linux creates two.
The root cause is likely an implementation difference between OS X's and Linux's sh
program. Even if you just give it a single absolute path to an executable file, Ruby will always spawn a subshell if you pass just one argument to Kernel#exec
. Both shells, if given an exact absolute path, will directly exec(2)
(or whatever