简体   繁体   English

退出非root用户的ssh后,如何保持Linux程序运行?

[英]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 ,您还可以在终端多路复用器(如screentmux运行程序。 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会话结束后,有两个信号可能导致程序死亡: SIGHUPSIGPIPE

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会话后尝试写入stdoutstderrSIGPIPE将被发送到您的程序。 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 &

You might also want to use the batch (or at ) command, in addition to the other answers ( nohup , screen , ...). 除了其他答案( nohupscreen ,...)之外,您可能还想使用batch (或at )命令。 And ssh has a -f option which might interest you. 并且ssh有一个-f选项可能会让你感兴趣。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以root用户身份运行bash脚本后,如何让脚本自动强制我的用户退出root用户? - After running a bash script as root user, how can I have the script automatically force my user to exit root? 如何让我的 kernel 模块的 sysfs 条目归非 root 用户所有? - How do I make my kernel module's sysfs entry be owned by a non-root user? Linux / Python如何将root访问py模块作为非r​​oot用户导入? - Linux/Python How do I import a root access py module as a non-root user? Linux-以非超级用户身份运行超级用户安装的程序 - Linux - running root installed program as non-root 如何让我的脚本在 ssh 断开连接后继续运行而不强制它进入后台? - How can I make my script keep running after a ssh disconnect without forcing it to be backgrounded? 我不能 su 到非 root 用户 - I can't su to non-root user 如何以root身份启动Java程序,但降级为非root用户 - How to start Java program as root but downgrade to non-root user 如何在 cloud-init 配置期间为非 root 用户运行 shell 命令? - How can I run shell commands for non-root user during cloud-init configuration? 如何在Redhat Linux上以非root用户身份安装ReviewBoard? - How to install ReviewBoard as a non-root user on Redhat Linux? 有没有我可以以非root用户身份运行的命令,以查看用户是否可以运行某些sudo命令 - Is there a command I can run as a non-root user to see if a user can run a certain sudo command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM