从ssh注销后如何让程序继续运行? [英] How to make a program continue to run after log out from ssh?

查看:24
本文介绍了从ssh注销后如何让程序继续运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
防止后台进程在之后停止关闭 SSH 客户端

我有一个需要很长时间才能完成的程序.它以 root 身份通过 ssh 运行.
我希望它在我注销后继续运行,这可能吗,我将如何实现?

I have a program that takes a lot of time to finish. It is running as root over ssh.
I want it to continue to run after I logout,is this possible and how would I achieve this?

推荐答案

假设你有一个程序在前台运行,按ctrl-Z,然后:

Assuming that you have a program running in the foreground, press ctrl-Z, then:

[1]+  Stopped                 myprogram
$ disown -h %1
$ bg 1
[1]+ myprogram &
$ logout

如果只有一项工作,则无需指定工作编号.只需使用 disown -hbg.

If there is only one job, then you don't need to specify the job number. Just use disown -h and bg.

你按 ctrl-Z.系统暂停正在运行的程序,显示作业编号和已停止"消息,并返回到 bash 提示符.

You press ctrl-Z. The system suspends the running program, displays a job number and a "Stopped" message and returns you to a bash prompt.

您输入 disown -h %1 命令(这里,我使用了 1,但您将使用 1 中显示的作业编号code>Stopped 消息),它标记了作业,因此它忽略 SIGHUP 信号(它不会因注销而停止).

You type the disown -h %1 command (here, I've used a 1, but you'd use the job number that was displayed in the Stopped message) which marks the job so it ignores the SIGHUP signal (it will not be stopped by logging out).

接下来,使用相同的作业编号键入 bg 命令;这将在后台恢复程序的运行,并显示一条消息确认.

Next, type the bg command using the same job number; this resumes the running of the program in the background and a message is displayed confirming that.

您现在可以注销,它会继续运行..

You can now log out and it will continue running..

这篇关于从ssh注销后如何让程序继续运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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