Article directory
jar package running
windows and linux are the samejava -jar
Run when terminal is not closed
java -jar xxx.jar
: The current ssh window is locked and no other operations can be performed. Ctrl + c or directly close the window to stop the program; : The
java -jar xxxxx.jar &
current ssh window is not locked and other operations can be performed. When the window is closed, the program exits; : The program is suspended
nohup java -jar xxx.jar &
in the background. The program stops when the account is logged out or the terminal is closed, and the log file is stored in the nohup.out file in the current directory;
Terminal closes background running
nohup java -jar xxxxxx.jar > log.txt &
: Specify the output log to the log.txt file and suspend the program in the background. When the account is logged out or the terminal is closed, the program is still running;
nohup
It means generating a log file nohup.out
and &
starting a new thread in the background to execute the command.
View the running jar package
The following commands can be used
ps -ef | grep java
to view the currently running java process,
ps -ef | grep xxx.jar
view the currently running jar process,
ps -ef
view all processes, and see which columns are PID and PPID.
Termination of jar
kill -9 jar包pid
jar start and stop script
# start.sh
nohup java -jar 包名.jar >log.txt &
echo $! > /var/run/包名.pid
# 将jar包启动对应的pid写入文件中,为停止时提供pid
# shutdown.sh
PID=$(cat /var/run/包名.pid)
kill -9 $PID
Add executable permissions to the script
sudo chmod +x ./test.sh