Spawn a background process in Ruby

前端 未结 2 1655
再見小時候
再見小時候 2020-11-29 04:37

I\'m writing a ruby bootstrapping script for a school project, and part of this bootstrapping process is to start a couple of background processes (which are written and fun

相关标签:
2条回答
  • 2020-11-29 04:58

    better way to pseudo-deamonize:

    `((/path/to/deamon1 &)&)` 
    

    will drop the process into it's own shell.

    best way to actually daemonize:

    `service daemon1 start`
    

    and make sure the server/user has permission to start the actual daemon. check out 'deamonize' tool for linux to set up your deamon.

    0 讨论(0)
  • 2020-11-29 05:06

    As long as you are working on a POSIX OS you can use fork and exec.

    fork = Create a subprocess

    exec = Replace current process with another process

    You then need to inform that your main-process is not interested in the created subprocesses via Process.detach.

    job1 = fork do
      exec "/path/to/daemon01"
    end
    
    Process.detach(job1)
    
    ...
    
    0 讨论(0)
提交回复
热议问题