Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method · added in Ruby 3.1

Process._fork

() -> ::Integer
Process._fork → integer

An internal API for fork. Do not call this method directly. Currently, this is called via Kernel#fork, Process.fork, and IO.popen with "-".

This method is not for casual code but for application monitoring libraries. You can add custom code before and after fork events by overriding this method.

Note: Process.daemon may be implemented using fork(2) BUT does not go through this method. Thus, depending on your reason to hook into this method, you may also want to hook into that one. See this issue for a more detailed discussion of this.

Ruby version changes

  1. 3.1
    • Process._fork is added. This is a core method for fork(2). Do not call this method directly; it is called by existing fork methods: Kernel.#fork, Process.fork, and IO.popen(“-”). Application monitoring libraries can overwrite this method to hook fork events. [Feature #17795]

See also .exit! .fork .exit .getpgid also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1