ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Kajsa.Ander...@thomson.com>
Subject RE: AW: how to get a process id from a spawned task?
Date Wed, 13 Jun 2007 18:28:57 GMT
This snippet doesn't exactly give you the PID, but it gives something
that's close enough for what I needed (and may be sufficient for the
OP's use case, I'm not sure):

   import java.lang.management.ManagementFactory;
	...
   ManagementFactory.getRuntimeMXBean().getName(); // gets PID of
current process 

What this gives you is a string something like "2444@localhost"; we've
used it on Windows and on Linux. If all you want is the PID part, it's
simple enough to parse it out. 

As far as killing a process (in Windows), XP's Task Manager can display
PIDs as an additional column in the Processes tab...

Kajsa Anderson

-----Original Message-----
From: Steve Loughran [mailto:stevel@apache.org] 
Sent: Monday, June 11, 2007 4:25 AM
To: Ant Users List
Subject: Re: AW: how to get a process id from a spawned task?

arijit wrote:
> I was hoping not to use any 3rd party tool but maybe something via ANT

> tasks or Java calls. One of the similar threads mentioned about 'jps' 
> but could not get it working. Keeping it generic so that it can be 
> used not only for windows will be a good approach.
> 


well, the fact that even in java5 there's nothing in the Java APIs to
give you the process ID of a started process is going to make it hard. 
If someone knew how JPS worked (i.e. there was an official Java
interfact to whatever native lib is doing the heavy lifting, life would
be simpler

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message