You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by arijit <gh...@wipro.com> on 2007/06/08 15:00:36 UTC

Re: how to get a process id from a spawned task?

Being a newbie here, can you please elaborate a little more on how you
resolved this problem ?


Jay Dickon Glanville wrote:
> 
> Thanks.  That helped.  I used the <propertyregex> task from
> ant-contrib to retrieve just the process id, and then echoed that to
> the user.
> 
> Much appreciated.
> 
> JDG
> 
> On 5/28/07, Prashant Reddy <pr...@pramati.com> wrote:
>> If you are OK with using JDK 1.5, you could use 'jps' command that is
>> shipped with every JDK.
>>
>> See : http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
>>
>> Output of jps on my computer :
>> $ ~/programs/java/jdk1.5.0_10/bin/jps
>> 20608 Jps
>> 6550 Main
>>
>> You could perhaps use ANT's <exec> task to run this command.
>>
>> On Mon, 2007-05-28 at 08:19 -0400, Jay Dickon Glanville wrote:
>> > Hello all.
>> >
>> > Is there a way to get the process id (I'm dealing with a windows
>> > system here, but I believe the question could be asked of both windows
>> > an UNIX families) of a task that is spawned?  I have a java task:
>> >   <java spawn="true" ... />
>> > and I'd like to be able to echo the process id to the user (so that
>> > they can kill the process if they so desire).
>> >
>> > Is there a convenient way to get the process id?
>> >
>> > Thanks
>> >
>> --
>>
>> -Prashant
>>
>> Don't upload, just share : www.dekoh.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
> 
> 
> -- 
> Jay Dickon Glanville
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11025969
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: AW: how to get a process id from a spawned task?

Posted by arijit <gh...@wipro.com>.
Sun's documentation states that JPS may not be supported in future versions
of JDK.. also, it is not supported in Windows 98 and Windows ME... So I
guess JPS will not be a good choice after all...  

with no other generic support to retrieve process ids and take some action
based on the status, it seems to be restricted to using 3rd party tools...   
:(


Steve Loughran wrote:
> 
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11057997
Sent from the Ant - Users mailing list archive at Nabble.com.


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


RE: AW: how to get a process id from a spawned task?

Posted by Ka...@thomson.com.
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


Re: AW: how to get a process id from a spawned task?

Posted by Steve Loughran <st...@apache.org>.
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


Re: AW: how to get a process id from a spawned task?

Posted by arijit <gh...@wipro.com>.
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.



Gilbert Rebhan wrote:
> 
> Hi,
> 
> 
> arijit wrote:
>> I was thinking more of listing the current running processes in windows
>> and
>> then killing one of them.
> 
> if you're runnning on windows maybe you can go via <exec> combined with 
> PSKILL which is part of the PTOOLS suite, formerly Sysinternals now 
> under the hood of Mystersoft =
> 
> http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/PsTools.mspx
> http://www.microsoft.com/technet/sysinternals/utilities/pskill.mspx
> 
> " kill processes by name or process ID "
> 
> never tried it myself, give it a shot.
> 
> 
> Regards, Gilbert
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11056881
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: AW: how to get a process id from a spawned task?

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi,


arijit wrote:
> I was thinking more of listing the current running processes in windows and
> then killing one of them.

if you're runnning on windows maybe you can go via <exec> combined with 
PSKILL which is part of the PTOOLS suite, formerly Sysinternals now 
under the hood of Mystersoft =

http://www.microsoft.com/technet/sysinternals/ProcessesAndThreads/PsTools.mspx
http://www.microsoft.com/technet/sysinternals/utilities/pskill.mspx

" kill processes by name or process ID "

never tried it myself, give it a shot.


Regards, Gilbert



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


Re: AW: how to get a process id from a spawned task?

Posted by arijit <gh...@wipro.com>.
I was thinking more of listing the current running processes in windows and
then killing one of them.


Knuplesch, Jürgen wrote:
> 
> As far as I know, there is the possibilty to set a timeout, if that is
> waht you want! 
> 
> 
> -- 
> Jürgen Knuplesch                    www.icongmbh.de
> icon Systemhaus GmbH                Tel. +49 711 806098-275
> Sophienstraße 40                    
> D-70178 Stuttgart                   Fax. +49 711 806098-299
> 
> Geschäftsführer: Uwe Seltmann
> HRB Stuttgart 17655
> USt-IdNr.: DE 811944121 
> -----Ursprüngliche Nachricht-----
> Von: arijit [mailto:ghosh.arijit@wipro.com] 
> Gesendet: Freitag, 8. Juni 2007 15:39
> An: user@ant.apache.org
> Betreff: Re: how to get a process id from a spawned task?
> 
> 
> I followed the suggestion that Prashant had provided and executed jps from
> within ant by using <exec>. However, if I want to kill a process running
> under windows, how will I be able to do that ?
> 
> 
> arijit wrote:
>> 
>> Being a newbie here, can you please elaborate a little more on how you 
>> resolved this problem ?
>> 
>> 
>> Jay Dickon Glanville wrote:
>>> 
>>> Thanks.  That helped.  I used the <propertyregex> task from 
>>> ant-contrib to retrieve just the process id, and then echoed that to 
>>> the user.
>>> 
>>> Much appreciated.
>>> 
>>> JDG
>>> 
>>> On 5/28/07, Prashant Reddy <pr...@pramati.com> wrote:
>>>> If you are OK with using JDK 1.5, you could use 'jps' command that 
>>>> is shipped with every JDK.
>>>>
>>>> See : http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
>>>>
>>>> Output of jps on my computer :
>>>> $ ~/programs/java/jdk1.5.0_10/bin/jps
>>>> 20608 Jps
>>>> 6550 Main
>>>>
>>>> You could perhaps use ANT's <exec> task to run this command.
>>>>
>>>> On Mon, 2007-05-28 at 08:19 -0400, Jay Dickon Glanville wrote:
>>>> > Hello all.
>>>> >
>>>> > Is there a way to get the process id (I'm dealing with a windows 
>>>> > system here, but I believe the question could be asked of both 
>>>> > windows an UNIX families) of a task that is spawned?  I have a java
>>>> task:
>>>> >   <java spawn="true" ... />
>>>> > and I'd like to be able to echo the process id to the user (so 
>>>> > that they can kill the process if they so desire).
>>>> >
>>>> > Is there a convenient way to get the process id?
>>>> >
>>>> > Thanks
>>>> >
>>>> --
>>>>
>>>> -Prashant
>>>>
>>>> Don't upload, just share : www.dekoh.com
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>>>> additional commands, e-mail: user-help@ant.apache.org
>>>>
>>>>
>>> 
>>> 
>>> --
>>> Jay Dickon Glanville
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>>> additional commands, e-mail: user-help@ant.apache.org
>>> 
>>> 
>>> 
>> 
>> 
> 
> --
> View this message in context:
> http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11026651
> Sent from the Ant - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11027290
Sent from the Ant - Users mailing list archive at Nabble.com.


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


AW: how to get a process id from a spawned task?

Posted by Knuplesch, Jürgen <Ju...@icongmbh.de>.
As far as I know, there is the possibilty to set a timeout, if that is waht you want! 


-- 
Jürgen Knuplesch                    www.icongmbh.de
icon Systemhaus GmbH                Tel. +49 711 806098-275
Sophienstraße 40                    
D-70178 Stuttgart                   Fax. +49 711 806098-299

Geschäftsführer: Uwe Seltmann
HRB Stuttgart 17655
USt-IdNr.: DE 811944121 
-----Ursprüngliche Nachricht-----
Von: arijit [mailto:ghosh.arijit@wipro.com] 
Gesendet: Freitag, 8. Juni 2007 15:39
An: user@ant.apache.org
Betreff: Re: how to get a process id from a spawned task?


I followed the suggestion that Prashant had provided and executed jps from within ant by using <exec>. However, if I want to kill a process running under windows, how will I be able to do that ?


arijit wrote:
> 
> Being a newbie here, can you please elaborate a little more on how you 
> resolved this problem ?
> 
> 
> Jay Dickon Glanville wrote:
>> 
>> Thanks.  That helped.  I used the <propertyregex> task from 
>> ant-contrib to retrieve just the process id, and then echoed that to 
>> the user.
>> 
>> Much appreciated.
>> 
>> JDG
>> 
>> On 5/28/07, Prashant Reddy <pr...@pramati.com> wrote:
>>> If you are OK with using JDK 1.5, you could use 'jps' command that 
>>> is shipped with every JDK.
>>>
>>> See : http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
>>>
>>> Output of jps on my computer :
>>> $ ~/programs/java/jdk1.5.0_10/bin/jps
>>> 20608 Jps
>>> 6550 Main
>>>
>>> You could perhaps use ANT's <exec> task to run this command.
>>>
>>> On Mon, 2007-05-28 at 08:19 -0400, Jay Dickon Glanville wrote:
>>> > Hello all.
>>> >
>>> > Is there a way to get the process id (I'm dealing with a windows 
>>> > system here, but I believe the question could be asked of both 
>>> > windows an UNIX families) of a task that is spawned?  I have a java task:
>>> >   <java spawn="true" ... />
>>> > and I'd like to be able to echo the process id to the user (so 
>>> > that they can kill the process if they so desire).
>>> >
>>> > Is there a convenient way to get the process id?
>>> >
>>> > Thanks
>>> >
>>> --
>>>
>>> -Prashant
>>>
>>> Don't upload, just share : www.dekoh.com
>>>
>>>
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>>> additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>> 
>> 
>> --
>> Jay Dickon Glanville
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For 
>> additional commands, e-mail: user-help@ant.apache.org
>> 
>> 
>> 
> 
> 

--
View this message in context: http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11026651
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
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


Re: how to get a process id from a spawned task?

Posted by arijit <gh...@wipro.com>.
I followed the suggestion that Prashant had provided and executed jps from
within ant by using <exec>. However, if I want to kill a process running
under windows, how will I be able to do that ?


arijit wrote:
> 
> Being a newbie here, can you please elaborate a little more on how you
> resolved this problem ?
> 
> 
> Jay Dickon Glanville wrote:
>> 
>> Thanks.  That helped.  I used the <propertyregex> task from
>> ant-contrib to retrieve just the process id, and then echoed that to
>> the user.
>> 
>> Much appreciated.
>> 
>> JDG
>> 
>> On 5/28/07, Prashant Reddy <pr...@pramati.com> wrote:
>>> If you are OK with using JDK 1.5, you could use 'jps' command that is
>>> shipped with every JDK.
>>>
>>> See : http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html
>>>
>>> Output of jps on my computer :
>>> $ ~/programs/java/jdk1.5.0_10/bin/jps
>>> 20608 Jps
>>> 6550 Main
>>>
>>> You could perhaps use ANT's <exec> task to run this command.
>>>
>>> On Mon, 2007-05-28 at 08:19 -0400, Jay Dickon Glanville wrote:
>>> > Hello all.
>>> >
>>> > Is there a way to get the process id (I'm dealing with a windows
>>> > system here, but I believe the question could be asked of both windows
>>> > an UNIX families) of a task that is spawned?  I have a java task:
>>> >   <java spawn="true" ... />
>>> > and I'd like to be able to echo the process id to the user (so that
>>> > they can kill the process if they so desire).
>>> >
>>> > Is there a convenient way to get the process id?
>>> >
>>> > Thanks
>>> >
>>> --
>>>
>>> -Prashant
>>>
>>> Don't upload, just share : www.dekoh.com
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>> 
>> 
>> -- 
>> Jay Dickon Glanville
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-get-a-process-id-from-a-spawned-task--tf3827737.html#a11026651
Sent from the Ant - Users mailing list archive at Nabble.com.


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