Spawn a background process in Ruby

北慕城南 提交于 2019-11-27 00:59:05

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)

...

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!