How to turn off Cassandra or tomcat

Source: Internet
Author: User
Tags cassandra pkill
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.