简体   繁体   中英

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

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
   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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM