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 "[EMAIL PROTECTED]"; 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:[EMAIL PROTECTED] 
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: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to