java - 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?!
解决方案
这是预期的行为。如果您想在关闭 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
推荐阅读
- javascript - 发送 Java 数组作为 JavaScript 参数
- pygame - Pygame 已安装但我有一个“导入错误:没有名为“pygame”的模块
- javascript - JSDoc:嵌套函数的@type
- c# - 对 Google 云端硬盘文件的部分请求未返回预期内容
- python - 为什么 Selenium 的 wait.until_not(EC.invisibility_of_element_located) 等待加载器消失的时间太长?
- javascript - 如何使用月度或年度图表 PHP MySQL 显示数据库中的项目名称
- java - 如何从一个字符串中删除不同的字符串?
- javascript - 如何在模板中使用返回值的函数?Vuex, Vue
- python - (Numpy 或 PyTorch)对给定的 bin 求和数组元素
- apache-spark - 如何将表数据加载到数据块中的数据框中?逐行还是批量?