在后台运行 Ruby 脚本 [英] Run Ruby script in the background

查看:46
本文介绍了在后台运行 Ruby 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Ruby 脚本,我需要在我的 Linux 机器中一直运行它.我试过 nohup ruby​​ ruby​​.rb& 但它似乎不起作用.

I have a Ruby script that I need to have running all the time in my Linux box. I tried nohup ruby ruby.rb& but it seems it doesn't work.

如何让脚本在后台运行?

How can I have the script running in background?

推荐答案

看看 screen 这是一个命令行实用程序.从

Have a look at screen which is a command-line utility. Start it with

screen

您将获得一个分离的新外壳.用

You will get a new shell which is detached. Start your script there with

ruby whatever.rb

然后看着它运行.然后点击 Ctrl-A Ctrl-D,你应该回到原来的 shell.您现在可以离开 ssh 会话,脚本将继续运行.稍后,登录到您的框并键入

And watch it run. Then hit Ctrl-A Ctrl-D and you should be back at your original shell. You can leave the ssh session now, and the script will continue running. At a later time, login to your box and type

screen -r

你应该回到分离的外壳.

and you should be back to the detached shell.

如果您多次使用 screen,您将不得不通过 pid 选择 screen 会话,这不太舒服.为了简化,你可以这样做

If you use screen more than once, you will have to select the screen session by pid which is not so comfortable. To simplify, you can do

screen -S worker

开始会话和

screen -r worker

恢复它.

这篇关于在后台运行 Ruby 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆