Linux 从ssh注销后如何使程序继续运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/954302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 17:23:49  来源:igfitidea点击:

How to make a programme continue to run after log out from ssh?

linuxbashssh

提问by omg

Possible Duplicate:
Prevent a background process from being stopped after closing SSH client

可能的重复:
防止在关闭 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?

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

采纳答案by Paused until further notice.

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

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

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

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

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

Explanation of the above steps:

上述步骤的说明:

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.

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

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

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

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

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

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

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

回答by diciu

Start in the background:

在后台启动:

./long_running_process options &

And disown the job before you log out:

并在您注销之前否认该工作:

disown

回答by paxdiablo

You should try using nohupand running it in the background:

您应该尝试nohup在后台使用和运行它:

nohup sleep 3600 &

回答by Janusz

I would try the program screen.

我会尝试程序屏幕

回答by brndnmg

You could use screen, detach and reattach

您可以使用screen、分离和重新连接