tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: [OT] How to obtain the id of the current process
Date Wed, 17 Nov 2010 21:50:21 GMT
I found the following trick somewhere, maybe it works for you :

When starting your JVM, use a line like

java -Dpid=$$ program.java
and in the java program using the statement System.getProperty("pid");

If it works, it's cute, and certainly a lot less overhead.

Credits : http://www.jguru.com/faq/view.jsp?EID=416212
(last one)

Leon Rosenberg wrote:
> Hi,
> 
> I have a ugly issue I'm sure many people on this list already solved.
> For multiple purposes I need pid's of processes, to stop/start them or
> ensure they are running. So far nothing spectacular.
> To obtain the pid I have following util:
> 
> String[] cmd = { "/bin/bash", "-c", "echo $PPID" };
> p = Runtime.getRuntime().exec(cmd);
> 
> and afterwards read the ppid from the output stream of my process. So
> far - so good.
> 
> The problem now occurs if a process has a lot of memory configured.
> Like 25Gb on a 32Gb machine. In such a configuration the above command
> fails with an OS'es out of memory, because fork
> fails to create another process with THAT amount of memory:
> 
> 1598388 2010-11-17 02:54:47,061 ERROR net.anotheria.util.PidTools -
> Could not determine PID: java.io.IOException: Cannot run program
> "/bin/bash": java.io.IOException: error=12, Cannot allocate memory
> 
> Is there another method to obtain the process id from within the process?
> 
> regards
> Leon
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message