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
How to make a programme continue to run after log out from ssh?
提问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 -h
and bg
.
如果只有一项工作,则无需指定工作编号。只需使用disown -h
和bg
。
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 %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).
您键入disown -h %1
命令(在这里,我使用了1
,但您将使用Stopped
消息中显示的作业编号),该命令标记作业以便它忽略SIGHUP
信号(它不会因注销而停止)。
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.
接下来,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