Feature #2619

Proposed method: Process.fork_supported?

Added by hongli (Hongli Lai) about 10 years ago. Updated almost 9 years ago.

Target version:


It used to be that Process.fork is available on all POSIX platforms. With Ruby 1.9 that is no longer the case thanks to the fact that pthreads and fork cannot be combined on some platforms (CANNOT_FORK_WITH_PTHREAD). This makes it difficult to determine whether the current Ruby interpreter supports forking without actually calling fork.

I propose a method Process.fork_supported? which returns whether fork is supported on the current platform. See attached patch.

I realize that Process.spawn is the recommended way on Ruby 1.9 to spawn subprocesses, but there are times when forking without exec() is more efficient. I want to be able to use fork on platforms where it is fully supported, falling back to Process.spawn otherwise.

Specific use case:
Phusion Passenger is a Ruby web application server. It tries to conserve memory and reduce startup time by preloading an application's source code into a process, then forking multiple child processes that act as worker processes. This way spawning N worker instances of an application only takes L + N * F time instead of N * (L + F) time, where:

  • L = the time it takes to load the source code
  • F = the time it takes to fork a process =end


Also available in: Atom PDF