How can I get current PID from within Ant?
ant
Solution
You can find PID using java process monitoring tool JPS, then output stream can be filtered and if needed process can be killed. check out this tomcat pid kill script:
<target name="tomcat.kill" depends="tomcat.shutdown">
<exec executable="jps">
<arg value="-l"/>
<redirector outputproperty="process.pid">
<outputfilterchain>
<linecontains>
<contains value="C:\tomcat\tomcat_node5\bin\bootstrap.jar"/>
</linecontains>
<replacestring from=" C:\tomcat\tomcat_node5\bin\bootstrap.jar"/>
</outputfilterchain>
</redirector>
</exec>
<exec executable="taskkill" osfamily="winnt">
<arg value="/F"/>
<arg value="/PID"/>
<arg value="${process.pid}"/>
</exec>
<exec executable="kill" osfamily="unix">
<arg value="-9"/>
<arg value="${process.pid}"/>
</exec>
</target>
Problem
I have an ant task, and within it I'd like to get the current process id (a la `echo $PPID` from command line). I'm running `ksh` on Solaris, so I thought I could just do this: ``` <property environment="env" /> <target name="targ"> <echo message="PID is ${env.PPID}" /> <echo message="PID is ${env.$$}" /> </target> ``` But that didn't work; the variables aren't substituted. Turns out `PPID`, `SECONDS`, and certain other env variables don't make it into Ant's representation. Next I try this: ``` <target name="targ"> <exec executable="${env.pathtomyfiles}/getpid.sh" /> </target> ``` `getpid.sh` looks like this: ``` echo $$ ``` This gets me the PID of the spawned shell script. Closer, but not really what I need. I just want my current process ID, so I can make a temporary file with that value in the name. Any thoughts?