skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2.    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search