How do I kill this tomcat process in Terminal?

JavaLinuxUnixTomcatTerminal

Java Problem Overview


Using ps -ef | grep tomcat I found a tomcat server that is running. I tried kill -9 {id} but it returns "No such process." What am I doing wrong?

Here's an example:

Admins-MacBook-Pro:test-parent tom.maxwell$ ps -ef | grep tomcat
2043706342 39707 39695   0  3:40PM ttys000    0:00.00 grep tomcat
Admins-MacBook-Pro:test-parent tom.maxwell$ kill -9 39707
-bash: kill: (39707) - No such process

Java Solutions


Solution 1 - Java

There is no need to know Tomcat's pid (process ID) to kill it. You can use the following command to kill Tomcat:

pkill -9 -f tomcat

Solution 2 - Java

> ps -ef | grep tomcat | awk '{print $2}' | xargs kill -9

https://gist.github.com/nrshrivatsan/1d2ea4fcdcb9d1857076

Part 1

> ps -ef | grep tomcat => Get all processes with tomcat grep

Part 2

Once we have process details, we pipe it into the part 2 of the script

> awk '{print $2}' | xargs kill -9 => Get the second column [Process id] and kill them with -9 option

Hope this helps.

Solution 3 - Java

Tomcat is not running. Your search is showing you the grep process, which is searching for tomcat. Of course, by the time you see that output, grep is no longer running, so the pid is no longer valid.

Solution 4 - Java

just type the below command in terminal

ps -ef |grep 'catalina'

copy the value of process id then type the following command and paste process id

 kill -9 processid

Solution 5 - Java

As others already noted, you have seen the grep process. If you want to restrict the output to tomcat itself, you have two alternatives

  • wrap the first searched character in a character class

      ps -ef | grep '[t]omcat'
    

This searches for tomcat too, but misses the grep [t]omcat entry, because it isn't matched by [t]omcat.

  • use a custom output format with ps

      ps -e -o pid,comm | grep tomcat
    

This shows only the pid and the name of the process without the process arguments. So, grep is listed as grep and not as grep tomcat.

Solution 6 - Java

ps -Af | grep "tomcat" | grep -v grep | awk '{print$2}' | xargs kill -9

Solution 7 - Java

In tomcat/bin/catalina.sh

add the following line after just after the comment section ends:

CATALINA_PID=someFile.txt

then, to kill a running instance of Tomcat, you can use:

kill -9 `cat someFile.txt`

Solution 8 - Java

ps -ef

will list all your currently running processes

| grep tomcat

will pass the output to grep and look for instances of tomcat. Since the grep is a process itself, it is returned from your command. However, your output shows no processes of Tomcat running.

Solution 9 - Java

This worked for me:

Step 1 : echo ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'

This above command return "process_id"

Step 2: kill -9 process_id
// This process_id same as Step 1: output

Solution 10 - Java

this works very well (find tomcat processes and kill them forcibly)

ps -ef | grep tomcat | awk '{print $2}' | xargs kill -9

Solution 11 - Java

I had to terminate activeMQ java process among many java processes on the server, and this one is started by the specific user (username is activemq). So good way of separating may be to start a process by a specific user :

ps -ef | grep "activemq" | awk '{print $2}' | xargs kill -9

Solution 12 - Java

as @Aurand to said, tomcat is not running. you can use the

ps -ef |grep java | grep tomcat command to ignore the ps programs.

worked for me in the shell scripte files.

Solution 13 - Java

kill -9 $(ps -ef | grep 8084 | awk 'NR==2{print $2}')

NR is for the number of records in the input file. awk can find or replaces text

Solution 14 - Java

To kill a process by name I use the following

ps aux | grep "search-term" | grep -v grep | tr -s " " | cut -d " " -f 2 | xargs kill -9

The tr -s " " | cut -d " " -f 2 is same as awk '{print $2}'. tr supressess the tab spaces into single space and cut is provided with <SPACE> as the delimiter and the second column is requested. The second column in the ps aux output is the process id.

Solution 15 - Java

For mac users,

This is the only solution working for me.

sudo kill -9 `sudo lsof -t -i:8080`

Note: replace 8080 with your port number

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTom MaxwellView Question on Stackoverflow
Solution 1 - JavaDarshanView Answer on Stackoverflow
Solution 2 - JavasuryakrupaView Answer on Stackoverflow
Solution 3 - JavaAurandView Answer on Stackoverflow
Solution 4 - JavaASRView Answer on Stackoverflow
Solution 5 - JavaOlaf DietscheView Answer on Stackoverflow
Solution 6 - JavaVaibhavView Answer on Stackoverflow
Solution 7 - JavaShrikar KulkarniView Answer on Stackoverflow
Solution 8 - JavaChris KnightView Answer on Stackoverflow
Solution 9 - Javajaydip jadhavView Answer on Stackoverflow
Solution 10 - JavaPravin BansalView Answer on Stackoverflow
Solution 11 - JavadobrivojeView Answer on Stackoverflow
Solution 12 - JavaccjeatyView Answer on Stackoverflow
Solution 13 - Javauser8357232View Answer on Stackoverflow
Solution 14 - JavaPrathik Rajendran MView Answer on Stackoverflow
Solution 15 - JavaRanjithkumarView Answer on Stackoverflow