How do I kill this tomcat process in Terminal?

后端 未结 14 1550
渐次进展
渐次进展 2021-01-30 01:23

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?

相关标签:
14条回答
  • 2021-01-30 01:58
    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.

    0 讨论(0)
  • 2021-01-30 02:03

    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.

    0 讨论(0)
  • 2021-01-30 02:03

    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.

    0 讨论(0)
  • 2021-01-30 02:11

    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.

    0 讨论(0)
  • 2021-01-30 02:14
    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 讨论(0)
  • 2021-01-30 02:15

    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`
    
    0 讨论(0)
提交回复
热议问题