From: Robert Klemme Date: 2012-02-02T20:59:25+09:00 Subject: Re: Starting a process and specifying its parent On Thu, Feb 2, 2012 at 8:29 AM, Victor Blaga wrote: > I need to start a (sub)process from inside a ruby script that will continue > to run after the ruby script itself has finished. > The way I'm doing stuff right now is by using Process.spawn - this works, > however the ppid of the child process is assigned to the script that was > used to start the process, and thus after the script finishes the spawned > (child) processes gets closed as well. No. Storing the PID of the child somewhere and stopping the child process are completely unrelated: 12:54:32 ~$ ruby19 -e 'p Process.spawn("bash", "-c", "sleep 10; echo from shell; date"); puts "from ruby #{Time.now}"' 228 from ruby 2012-02-02 12:54:41 +0100 12:54:41 ~$ from shell Thu, Feb 02, 2012 12:54:51 PM It must be something else which terminates the child. Do you close the terminal? > My question is what would be the best way to start such a (sub)process and > assign it a parent in such a way that it keeps running even after the > current script has ended? As a side-note, I also need to be able to capture > the stderr and assign it to a specific file (which works using > Process.spawn), but I'm not sure about the other methods. > I have to mention I'm using a linux machine but I'm unfortunately not very > familiar with the way linux process exactly work... You could do fork do $stdin.close $stdout.reopen "/dev/null" $stderr.reopen "/tmp/errors" exec "your_command", "with", "arguments" end You'll find more by searching for "demonize". Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/