by hand, here is the process:
ps -ef | grep tomcat
The results of this look like:
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
the second number is the pid.
Then I do
sudo kill tomcat_pid
How can I automate this?
ps. I know there is a shutdown.sh script. I’ve tried it but it never works.
ps -ef | grep tomcat | awk '{ print $2 }' | xargs killwill extract that second number and pass it tokill. Actually, you’ll probably wantps -efwwto make sure you get the whole command line.This really isn’t the nicest way to do this; ideally, you should store the PID when you create the process you’ll later want to kill, to make sure you don’t kill things that accidentally happen to match the string you’re searching for (amongst other potential problems).