59

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
1
  • 6
    That's actually grep searching for tomcat.
    – Ryan Amos
    Mar 5, 2013 at 23:45

15 Answers 15

176

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
3
  • 1
    short and crispy. BTW I have 2 tomcat one is tomcat 7 and another one is tomcat 5 process so it was killing 2. I used slightly different variant pkill -9 -f /tomcat7path and pkill -9 -f /tomcat5path so that I can kill one at a time. it was very easy to configure as alias as it doesnt have backticks and single quotes in the command .... Very good answer Aug 23, 2017 at 17:12
  • 1
    Note that "-f" matches all command-line arguments, not just the process name so even if the process name is "java", it will still match. "pgrep -f tomcat" shows what will match. Jul 30, 2018 at 20:03
  • "pkill -9 -f catalina" also works for me. My eclipse "java" process also has "tomcat" in the "ps -ef" but for some reason "pgrep -f tomcat" does not match it. Jul 30, 2018 at 20:03
22

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.

20

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.

1
  • 2
    Next time use ps -ef | grep [t]omcat
    – Bdloul
    Mar 5, 2013 at 23:55
16

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
2
  • 1
    this is the first one that worked for me on Linux Mint 18.3, the selected answer had no effect.
    – JesseBoyd
    Feb 17, 2018 at 22:39
  • This worked for me when tomcat is run via eclipse and the process name is "java". My other "java" process is eclipse. See related answer with "org.apache.catalina.startup.Bootstrap". Jul 30, 2018 at 19:17
12

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.

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

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`
2
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.

1

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

1

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.

1

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

ps -ef | grep tomcat | awk '{print $2}' | xargs kill -9
2
  • This returned 2 pids for me which one will it kill out of them?
    – Alpha
    May 17, 2020 at 11:46
  • It is better to use ps -ef | grep -i 'tomcat' | grep -v grep | awk '{print $2}' | xargs kill -9 to give you pids only of tomcat processes, excluding grep process. @Alpha, I suppose the second pid you have got was the pid of grep process itself.
    – Kyo
    Aug 26 at 8:49
0

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
0

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.

0
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

0

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.