A Ruby module that makes it easy to create child processes that die when their parent process is killed.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
spec
MIT-LICENSE.txt
README.rdoc
adeona.gemspec

README.rdoc

Introduction

Adeona is a Ruby module that makes it easy to create child processes that die when their parent process is disabled. It works even if the parent process is disabled with SIGKILL. It also avoids busy waiting. The code itself has been extensively commented so as to make it easy for others to modify it as desired.

Getting Started

Install the gem at the command prompt:

gem install adeona

Examples

Adeona has only one method called spawn_child(). Its syntax is very familiar to that of fork(). In the example below we create a child process that prints 'Hello World!':

# myapp.rb
require 'adeona'

child_pid = Adeona.spawn_child do
  puts 'Hello World!'
end

# don't let the main process exit immediately, as Adeona would make the child process
# exit before it might have had a chance to print 'Hello World!'.
sleep 5

Aside from a block, the spawn_child() method can also take an options hash that specifies a value for the :detach, :timeout, and :verbose symbols. These options are extensively commented in the source code. The code below shows how we can make the child process disable itself after 5 seconds:

# myapp.rb
require 'adeona'

child_pid = Adeona.spawn_child(:detach => false, :timeout => 5) do
  while(true) do
    puts 'child process is running'
  end
end

Process.waitpid(child_pid)