I am working on a plugin for the Serversoftware Bukkit which should restart it. So I have added the main Function which checks for the right arguments and then starts Bukkit. But before it starts Bukkit it should wait for Bukkit to shutdown before I start it again. I know I could add a timeout but I hope there is a better way. So does anybody know how to do that?
Asked
Active
Viewed 136 times
0
-
http://stackoverflow.com/questions/2318220/how-to-programmatically-detect-if-a-process-is-running-with-java-under-windows – While-E Aug 01 '12 at 22:28
-
1Yeah, I have seen that but I need a platform independ way – Max Jöhnk Aug 01 '12 at 22:33
-
For linux you can use jps command. For windows @While-E provided a solution – Masood_mj Aug 01 '12 at 23:10
2 Answers
0
-
1Also thought about that but unsure whether i will find the right process. The Idea was to add the process itself or the pid as an Argument but if you are running the client and the server on windows, they are both called java.exe. – Max Jöhnk Aug 01 '12 at 22:52
0
When you start multiple java processes they all seem to have the same identifiers, which seems to be your problem. "differentiating" the processes is your problem, not killing them.
So either you could create the process yourself programatically, and thus be able to note the PID that is used for the process. Then killing it would be VERY simple: http://blog.igorminar.com/2007/03/how-java-application-can-discover-its.html
Another idea would be to use JPS to get information on all the java processes. A simple sudo algorithm is discussed here: http://bluepedia.blogspot.com/2008/11/jps-differentiate-between-multiple-java.html
Hope I could be of some help..

While-E
- 1,527
- 2
- 20
- 37