首页 > 解决方案 > process gets killed on server when closing SSH session

问题描述

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?!

标签: javalinuxsshcentosputty

解决方案


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

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

Name the script : app.sh

示例脚本内容:

#!/bin/sh

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

转到脚本的位置:

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

Run the script as : ./app.sh

推荐阅读