3

手动,这里是过程:

ps -ef | grep tomcat

结果如下:

0 39107 1 0 5:40PM ttys004 5:22.34 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -Djava.util.logging.config.file=/opt/local/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xms384m -Xmx768m -XX:NewSize=256m -XX:NewRatio=2 -XX:PermSize=128m -XX:MaxPermSize=384m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=/opt/local/tomcat7/endorsed -classpath /opt/local/tomcat7/bin/bootstrap.jar:/opt/local/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/opt/local/tomcat7 -Dcatalina.home=/opt/local/tomcat7 -Djava.io.tmpdir=/opt/local/tomcat7/temp org.apache.catalina.startup.Bootstrap start

第二个数字是 pid。

然后我做

sudo kill tomcat_pid

我怎样才能自动化呢?

附言。我知道有一个shutdown.sh 脚本。我试过了,但它从来没有用过。

4

4 回答 4

7

ps -ef | grep tomcat | awk '{ print $2 }' | xargs kill将提取第二个数字并将其传递给kill. 实际上,您可能希望ps -efww确保获得整个命令行。

这确实不是最好的方法。理想情况下,您应该在创建稍后要杀死的进程时存储 PID,以确保您不会杀死意外发生的与您正在搜索的字符串匹配的东西(以及其他潜在问题)。

于 2012-06-27T14:57:57.073 回答
0

这是使用 bash 脚本杀死所有正在运行的 tomcat 进程的脚本

  #!/bin/sh
  ARG=$1 
  for file in `find /proc -regex /proc/[0-9]+ 2> /dev/null`; do
     if `grep --silent org.apache.catalina.startup.Bootstrap $file/cmdline 2> /dev/null`; then 
          base=`basename $file`
          echo "Trying to " kill $ARG $base "tomcat process"
          kill $ARG $base
     fi  
  done
于 2014-11-11T05:03:48.767 回答
0

this is my script for Ubuntu Linux uses bash its not automatic but finding and killing tomcat comes to
pressing enter if you do want to kill a process and typing process number manually.

#/bin/bash
if [ `whoami` != root ]; then
    echo "Please run this script as root or using sudo"
    exit
fi
echo
echo "finding proceses that have name java and established connections status"
echo
echo "Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name"
netstat --tcp --numeric --programs  | grep "ESTABLISHED" | grep "java"
echo 
echo "finding proceses that use port 8080"
echo
netstat --tcp --numeric --programs | grep ":8080" 
echo -n "Do you wish to kill a process listed above?[Y/n]"
read choose
if [ "$choose" = "Y" ] || [ "$choose" = "y" ] || [ -z "$choose" ]
then 
echo "enter pid to kill"
read procesId
kill -9 $procesId
fi
echo "done exiting"
exit 0
于 2012-09-18T00:22:13.013 回答
0

尝试:

pkill -f catalina; sleep 3

pkill:根据名称和其他查找或发送信号进程。
sleep 3:等待 3 秒,在尝试立即启动 tomcat 时很有用。

于 2015-10-06T21:47:31.310 回答