[英]How can I keep my Linux program running after I exit ssh of my non-root user?
I've searched, googled, sat in IRC for a week and even talked to a friend who is devoutly aligned with linux but I haven't yet received a solid answer. 我搜索,搜索,坐在IRC一个星期,甚至与一个虔诚地与Linux对齐的朋友交谈,但我还没有得到一个可靠的答案。
I have written a shell script that runs as soon as I log into my non-root user and runs basically just does "./myprogram &" without quotation. 我编写了一个shell脚本,一旦我登录到我的非root用户就会运行,并且基本上只运行“./myprogram&”而不引用。 When I exit shh my program times out and I am unable to connect to it until I log back in. How can I keep my program running after I exit SSH of my non-root user? 当我退出时,我的程序超时,我无法连接到它,直到我重新登录。在退出非root用户的SSH后,如何保持程序运行?
I am curious if this has to be done on the program level or what? 我很好奇是否必须在程序级别完成或者什么? My apologizes if this does not belong here, I am not sure where it goes to be perfectly honest. 如果这不属于这里我很抱歉,我不确定它在哪里是完全诚实的。
Beside using nohup
, you can run your program in terminal multiplexer like screen
or tmux
. 除了使用nohup
,您还可以在终端多路复用器(如screen
或tmux
运行程序。 With them, you can reattach to sessions, which is for example quite helpful if you need to run terminal-based interactive programs or long time running scripts over a unstable ssh connections. 使用它们,您可以重新连接到会话,例如,如果您需要运行基于终端的交互式程序或在不稳定的ssh连接上长时间运行脚本,这将非常有用。
boybu
is a nice enhancement of screen
. boybu
是一个很好的screen
增强功能。
Try nohup: http://linux.die.net/man/1/nohup 试试nohup: http : //linux.die.net/man/1/nohup
Likely your program receives a SIGHUP signal when you exit your ssh session. 退出ssh会话时,您的程序可能会收到SIGHUP信号。
There's two signals that can cause your program to die after your ssh
session ends: SIGHUP
and SIGPIPE
. 在ssh
会话结束后,有两个信号可能导致程序死亡: SIGHUP
和SIGPIPE
。
SIGHUP
will be sent to your program because the parent process ( ssh
) has died. 由于父进程( ssh
)已经死亡, SIGHUP
将被发送到您的程序。 You can get around this either by using the program nohup
(ie nohup ./myprogram &
) or by using the shell builtin disown
( ./myprogram& disown
) 您可以使用nohup
程序(即nohup ./myprogram &
)或使用shell builtin disown
( ./myprogram& disown
)来解决这个问题。
SIGPIPE
will be sent to your program if it tries to write to stdout
or stderr
after the ssh
session has been disconnected. 如果在断开ssh
会话后尝试写入stdout
或stderr
, SIGPIPE
将被发送到您的程序。 To get around this, redirect them to a file or /dev/null
, ie nohup ./myprogram >/dev/null 2>/dev/null &
要解决这个问题,请将它们重定向到文件或/dev/null
,即nohup ./myprogram >/dev/null 2>/dev/null &
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.