I wish to steer clear of the Tomcat process by its process ID. How do i obtain the Tomcat process ID using Java?
There's no direct means to access the PID that i'm conscious of, however, someone has written an excellent Blog regarding how to do that not directly. This is a connect to his 5 different choices.
The best choice is that one...
While using java management and monitoring API (java.lang.management):
returns something similar to: 28906@localhost where 28906 may be the PID of JVM's process, which is actually the PID of my application.
This hack is JVM dependent and that i examined it just with Sun's JVM.
From Javadocs for getName() approach to RuntimeMXBean: Returns the title representing the running Java virtual machine. The came back title string can be any arbitrary string along with a Java virtual machine implementation can decide to embed platform-specific helpful information within the came back title string. Each running virtual machine will have a different title.
I am unsure if the assists in the Home windows situation, however the
catalina.sh script which you can use on Linux / UNIX could be told to keep the PID from the process inside a file. You need to simply set the
CATALINA_PID atmosphere variable towards the pathname of the PID file. When you have carried this out, running
catalina.sh stop -force will endeavour a clean shutdown, and when that fails it'll
kill the Tomcat process.
You are able to execute TASKLIST.EXE in java and garb the end result. the 2nd option I discovered intresting is to operate Service stop command from java.
Hope it will help.