Implementation of jar Packet Startup and jar Packet Background Running in Linux
- 2021-07-03 01:08:45
- OfStack
Linux the command to run the jar package is as follows:
Mode 1:
java -jar shareniu.jar
Features: The current ssh window is locked. Press CTRL + C to interrupt the program, or close the window directly and the program exits
How to keep the window unlocked?
Mode 2
java -jar shareniu.jar &
& Represents running in the background.
Specific: The current ssh window is not locked, but when the window closes, the program stops running.
Continue to improve, how to make the program still run when the window is closed?
Mode 3
nohup java -jar shareniu.jar &
nohup means do not hang up the running command, when the account exits or the terminal closes, the program still runs
When a job is executed with the nohup command, all output from the job is redirected to the file of nohup. out by default, unless an output file is specified otherwise.
Mode 4
nohup java -jar shareniu.jar >temp.txt &
Under explanation > temp.txt
command > out.file
command > out. file redirects the output of command to the out. file file, that is, the output is not printed to the screen, but output to the out. file file.
Background running tasks can be viewed through jobs command
jobs
Then all jobs executed in the background are listed, and each job is preceded by a number.
If you want to bring a job back to foreground control, you only need fg + number.
fg 23
View the pid of threads occupied by a port
netstat -nlp |grep :9181
If you forget the process number, you can view the process number of the currently running jar package program by the following command
ps -ef|grep xxx.jar
Or
ps -aux | grep java
//Close the process
kill -s 9 24204
24204 represents the process ID detected in the previous step
Summarize