Start the jar package command in Linux

1. Start the jar package command

method one

java -jar XXX.jar

When running in this way, when the ssh window is locked, press CTRL + C to interrupt the program, or close the window directly, the program will exit

way two

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.

way three

nohup java -jar XXX.jar &

nohup means to run the command without hanging up. When the account is logged out or the terminal is closed, the program is still running. When the
nohup command is used to execute the job, by default all the output of the job is redirected to the nohup.out file, unless otherwise An output file is specified.

way four

//会阻塞
nohup java -jar XXX.jar >temp.txt &   
//不会阻塞
nohup java -jar XXX.jar >temp.txt 2>&1 &   

例子
nohup java -jar -Xms64m -Xmx512m -Dlegox.env=DEFAULT_GROUP -Dlegox.nacos.address=10.20.105.21:8848 /opt/env/jars/legox-power-bpm-release-0.0.1-SNAPSHOT.jar > ./logs/power-bpm.log 2>&1 &

2>&1: The meanings of the previous 2 and 1 are as follows:
0 standard input (usually the keyboard)
1 standard output (usually the display screen, which is the user terminal console)
2 standard error (error information output)

command >out.file is to redirect the output of the command to the out.file file, and the output content is not printed to the screen, but output to the out.file file.
2>&1 is to redirect the standard error to the standard output, because the standard output has been redirected to the out.file file, so the standard error is also output to the out.file file.
The last & is to let the command execute in the background.

2. View the running jar

1.ps to

ps aux | grep xx.jar

Explanation of aux
a Show processes for all users (show processes for all users)
u Show users (display the process's user/owner)
x Show processes without control terminals (also show processes not attached to a terminal)

2.ps -ef

ps -ef |grep xx.jar

The explanation of ef
ps -ef is displayed in the System V mode, which is more than the BSD mode.
e Display all user processes (all processes). The effect of this parameter is the same as specifying the "a" parameter.
f Use ASCII characters to display the tree Structure, expressing the relationship between programs (ASCII art forest)

3.jps

jps

The explanation of jps
The console lists the currently running java process

3. Kill the Java process

1.kill -9 (process id)

kill -9 PID is the operating system to forcibly kill a process from the kernel level.

2.kill -15 (process id)

kill -15 PID can be understood as the operating system sends a notification to tell the application to actively shut down
. When using kill -15, the system will send a SIGTERM signal to the corresponding program. When the program receives the signal, it is up to itself how to deal with it.
At this time, the application can choose:
1. Stop the program immediately
2. Stop the program after releasing the response resources
3. Ignore the signal and continue to execute the program
because the kill -15 signal only informs the corresponding process to perform a "safe and clean exit". After the program receives the signal, it will generally perform some "preparatory work" before exiting, such as resource release, temporary file cleaning, etc. If the preparatory work is completed, the program will be terminated. However, if during the "preparation" process, blocking or other problems prevent success, the application can choose to ignore the termination signal. This is why we sometimes use the kill command to "kill" the application, because the default kill signal is SIGTERM (15), and the signal of SIGTERM (15) can be blocked and ignored. Compared with kill -15, kill -9 is relatively tough. The system will send a SIGKILL signal, which requires the program that receives the signal to end running immediately and cannot be blocked or ignored. Therefore, compared to the kill -15 command, when the kill -9 command is executed, the application does not have time to "prepare", so this usually brings some side effects, such as data loss or the terminal cannot be restored to a normal state.

Guess you like

Origin blog.csdn.net/qq_37924396/article/details/128034122