Using nohup to run the jar file package program in the background under linux

The command to run the jar package in Linux is as follows:

method one:

 
  1. java -jar XXX.jar

Features: The current ssh window is locked, you can press CTRL + C to interrupt the program running, or directly close the window and the program exits

How can I keep the window from locking?

Method 2

 
  1. java -jar XXX.jar &

& stands for running in the background.

Specific: The current ssh window is not locked, but when the window is closed, the program aborts.

Continue to improve, how to make the program still run when the window is closed?

way three

nohup java -jar XXX.jar &

nohup means do not hang up running the command, when the account is logged out or the terminal is closed, the program still runs

When a job is executed with the nohup command, by default all output from the job is redirected to the file nohup.out, unless an output file is specified otherwise.

way four

 
  1. nohup java -jar XXX.jar >temp.txt &

Explain >temp.txt

command >out.file

command > out.file redirects the output of the command to the out.file file, that is, the output content is not printed to the screen, but is output to the out.file file.

You can view background running tasks through the jobs command

 
  1. jobs

Then all the jobs executed in the background are listed, and each job is preceded by a number.
If you want to call a job back to foreground control, you only need fg + number.

 
  1. fg 23

View the pid of the thread occupied by a port

netstat -nlp | grep: 9181

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326905724&siteId=291194637