Mode 0: the old-fashioned way
I used to like using kill-9 to close certain processes,
For example, to turn off Tomcat, often eat the following shell
Ps-ef | grep Tomcat | Grep-v grep | awk ' {print $} ' | Xargs kill-9
First Use Ps-ef | grep Tomcat detects Tomcat-related processes, and then uses grep-v grep to filter out the grep tomcat process, leaving the record of the process that needs to be closed, containing multiple pieces of information.
So we use awk to select the second item, the process ID, and then we pass the process ID that needs to be turned off to the kill command by the Xargs command, which kills the process we want to end, and the purpose of closing the program.
I used to think this is a good way, but recently saw a new way, the original shutdown can be so simple:
Let's use Cassandra as an example to explain how to close:
mode one: PID file mode
Use at startup:
Cassandra-p Cassandra.pid
The process ID is stored in the Cassandra.pid file at startup.
Use at end:
Pkill-f Cassandra.pid
mode two: Use name lookup method
No additional requirements are available at startup and can be started directly.
When closed, use name lookup, get the corresponding process ID and then close, which is consistent with the way it was said, but more elegant.
Pkill-u ' Id-un '-f Cassandra
First use the Id-un command to find the ID name of the current user, and then the-U uid to limit the lookup only to the user under change. The-f Cassandra is used to find the process ID that contains Cassandra in the command and then close directly.
Seems to be a lot simpler.
The difference between the two ways: the first way is slightly more troublesome, but can be accurately closed. The second way, when there are multiple similar names of the process is easy to manslaughter.