• Post Reply Bookmark Topic Watch Topic
  • New Topic

PID for a java application  RSS feed

 
Ajai
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am facing some problem whereby
I need to know the PID of a java application running on windows.
Can anybody provide a simple sol. for this ,I do not want to use JNI approach.


Thanks...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to use JNI, then you'll need a Java-COM bridge.

However, getting the PID of a java app will have the added problem that the process in Windows will be the JVM, not the app - because that's running inside the JVM. So if you have more than one JVM running you have absolutely no way of knowing which is the app you want.
 
Ajai
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx for your response.

In actual scenario , i will have more than one similar java apps running but they will be pointing to the same JDK.
Whats is this Java_COM bridge.
I would be grateful if you could elaborate on that.

Thanks..
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were to explain why you want to know the PID, someone might have an idea for a different solution to your problem.

I'm moving this to the Intermediate forum...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Java-COM bridge is a bridge between Java and COM. So you can wrap COM functionality in Java classes and therefore call COM functions from Java methods. Have a google for JIntegra, which is one of the best. Basically, its probably just a wrapper for all the JNI work you would have to do yourself if you didn't want to use a bridge.

As far as finding out a PID for a specific java app, that is not possible. Its the JVM which is the process in OS terms, not the Java app. Set some java apps going then look in your process explorer, all you'll probably see is a number of javaw.exe running, or something simmilar.
 
Ajai
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Basically we have some java app which can run on windows/unix m/c. We are running/stopping/monitoring that app through a J2EE app .
In unix case If I can get the pid for an application when I run it ,I store it in the db and when I have to stop that app. i use kill command with pid to stop that.At the same time I need to get the CPU and mem usage
for that java app hence I use ps command with pid to get that.

Now in windows I want an analogous operation basically I am thinking of using pid if I have to stop that application.Is there any other method available to do that.

Thanks Paul ,I will explore on JIntegra also.

Thanks...
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could implement your server as daemon-thread, which opens an own ctrl-port, and waits for an datagram.

Then you build a starter-App, which sends a datagram to that port.
If no answer is given, you assume the server is down, and start it.

The admin could start the starter with

and if the server is already running, you pass the command via the datagram to server, so he may terminate himself gracefully.

I wrote a 'proof of concept'- Fibonacci-Server, which works as intended, beside giving the wrong answer for 'info' when already running

Interesting observation I made while implementing:
(Maybe I should discuss this issue in 'Threads and ...').
The java-docs tell me, that a daemon will stop running, if only daemons are left, running in the JVM. (annoying! - why?)
I tried this, and yes - they stopped running.
But when I start my Starter with java Starter start &, which brings the whole jvm into the background, the daemons keep alive. So java-daemons and linux-daemons aren't the same.
I don't know how you could bring a Process to background in Windows (is it a real multitasking OS?)

[ May 28, 2004: Message edited by: Stefan Wagner ]
[ May 28, 2004: Message edited by: Stefan Wagner ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!