在关闭SSH会话时,服务器上的进程被终止。

huangapple go评论45阅读模式
英文:

process gets killed on server when closing SSH session

问题

我使用PuTTY通过SSH连接到我的Linux(CentOS 8)服务器,然后通过以下命令在服务器上运行我的Java程序:

java -cp /.../ app

一切都正常,程序持续运行,但当我在PuTTY中关闭SSH会话时,我的Java程序也被终止了。为什么会发生这种情况,如何防止它发生?

英文:

I use PuTTY to connect to my Linux (centos 8) server by SSH. then I run my java program on server by the command

java -cp /.../ app

everything is fine and the program runs continuously, but when I close my SSH session in PuTTY, my java program gets also killed. why it happens and how to prevent it?!

答案1

得分: 1

这是预期行为。如果您想在关闭SSH putty会话后继续运行您的Java JAR文件,请创建一个shell脚本并尝试通过运行shell脚本来运行Java应用程序。

以下是示例脚本,您可以根据需要进行修改:

将脚本命名为:app.sh

示例脚本内容:

#!/bin/sh

cd /home/user/    #您的jar文件所在的路径
java -jar app.jar

前往脚本所在位置:

为脚本app.sh赋予适当的执行权限:

chmod 755 app.sh

以以下方式运行脚本:./app.sh

英文:

This is an expected behavior. If you want to keep running your java jar file even though you close the SSH putty session , create a shell script and try to run the java application through running the shell script.

A sample script is shown below, you can modify according to your need :

Name the script : app.sh

Sample Script Content :

#!/bin/sh

cd /home/user/    #path where your jar file is kept
java -jar app.jar

Go to the location of the script :

Give proper execute permissions to the script app.sh :
chmod 755 app.sh

Run the script as : ./app.sh

答案2

得分: 0

nohup java -jar test.jar &

nohup 是一个POSIX命令,用于忽略HUP(挂起)信号。按照惯例,HUP信号是终端通知依赖进程注销的方式。

通常会输出到终端的内容会被重定向到一个叫做nohup.out的文件中,如果没有已经被重定向的话。

简而言之,它代表着不挂起。

英文:
   nohup java -jar test.jar &

nohup is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is, by convention, the way a terminal warns dependent processes of logout.

Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected.

In short, it stands for no hang up.

huangapple
  • 本文由 发表于 2020年8月2日 19:40:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63215551.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定