如何防止Nohup杀死等待stdin linux的java进程 [英] how to keep nohup from killing java process that waits for stdin linux
问题描述
我有一个在命令行(Bash Linux)上执行的Java程序.一旦执行,程序将继续运行,读取标准输入,直到用户输入退出".
I have a java program that is executed on command line (Bash Linux). Once executed the program continues to run, reading stdin until the user inputs 'quit'.
有时我想 nohup ,以便即使关闭远程连接,该程序也可以继续运行.问题是,当我尝试按以下所示方式对程序进行nohup时,似乎其输入stdin的提示会杀死nohup并终止该程序.
Sometimes I would like to nohup the program so it continues to run even if my remote connection is closed. The problem is that when I attempt to nohup the program as demonstrated below it seems that its prompt for stdin kills nohup and terminates the program.
示例:$ nohup java -jar myApp.jar
Example: $ nohup java -jar myApp.jar
我尝试将程序的输出重定向到其他建议 2>/dev/null ,并使用& 在后台运行它.两者都不能阻止nohup被杀死.
I have tried redirecting the program's output to 2>/dev/null per other suggestions as well as running it in the background using &. Neither prevents nohup from being killed.
我不能使用 disown ,因为一旦运行该程序,我将失去命令提示符.
I cannot use disown because once I run the program I lose the command prompt to the program.
推荐答案
要使程序在后台运行,请运行 tmux
:
To get your program running in the background, run tmux
:
tmux
这将打开一个tmux shell,您可以在其中运行程序:
This will open up a tmux shell, where you can run your program:
java -jar myApp.jar
然后要从tmux会话中分离,请键入 ctrl-b
,然后键入 d
.您的程序将继续在后台运行.
Then to detach from the tmux session, type ctrl-b
then d
. Your program will continue to run in the background.
要在以后重新连接到程序的外壳(杀死它或查看其输出),请运行 tmux attach
.
To reattach to your program's shell at a later time (to kill it or view its output), run tmux attach
.
这篇关于如何防止Nohup杀死等待stdin linux的java进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!