--f46d043748f3cbca6404b7fa0586
Content-Type: text/plain; charset=ISO-8859-1

Hi Robert,

Thank you for your answer. I've further investigated the issue and you are
right. I was also calling Process.detach on the pid of the child process.
When I read the documentation I falsely understood that this method would
detach the parent process from the child process, which in my opinion ment
that once the parent process finishes the child process remains. However it
seems that it has the opposite effect.

By not calling Process.detach once the parent process closes the child
process get's assigned as parentpid   (which is the master process or so
I understand).

Thank you and kind regards,
Victor

2012/2/2 Robert Klemme <shortcutter / googlemail.com>

> On Thu, Feb 2, 2012 at 8:29 AM, Victor Blaga <vic.blaga / gmail.com> 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/
>
>

--f46d043748f3cbca6404b7fa0586--