<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: fork code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 07:30:08 GMT</pubDate>
    <description>DZone Snippets: fork code</description>
    <item>
      <title>Daemonize a Ruby process</title>
      <link>http://snippets.dzone.com/posts/show/3646</link>
      <description>// description of your code here&lt;br /&gt;from : http://scie.nti.st/2006/12/15/daemonize-a-ruby-process&lt;br /&gt;Here's a neat thing I found. I needed a small bit of Ruby code to run continuously in the background, but because of how Capistrano can't seem to work well with "nohup" and "&amp;" (background job), my ruby script itself needed to be able to fork and detach from the terminal. Here's how you do it: &lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;pid = fork do&lt;br /&gt;  Signal.trap('HUP', 'IGNORE') # Don't die upon logout&lt;br /&gt;&lt;br /&gt;  loop do&lt;br /&gt;&lt;br /&gt;    // Some code&lt;br /&gt;&lt;br /&gt;    sleep 60&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Process.detach(pid)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 Mar 2007 09:42:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3646</guid>
      <author>Mickael (Mickael)</author>
    </item>
  </channel>
</rss>
