gpt4 book ai didi

ruby - 后台/守护进程

转载 作者:数据小太阳 更新时间:2023-10-29 07:42:46 32 4
gpt4 key购买 nike

我有一个按以下方式编码的脚本。我想将它作为后台/守护进程运行,但是一旦我启动脚本,如果我关闭它从程序运行的终端窗口终止。我需要做什么来保持程序运行

loop do

pid = fork do
..........
..........
..........
end

Process.detach(pid)
end

最佳答案

上面的所有答案都没有真正表明这样做有多么容易:

# Daemonize the process and stay in the current directory
Process.daemon(true)

loop do
pid = Process.fork do
# Do something funky
end

Process.waitpid(pid)

# Reduce CPU usage
sleep(0.1)
end

关于ruby - 后台/守护进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5449617/

32 4 0
文章推荐: ruby - 如何检查
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com