On Wed, Nov 17, 2010 at 11:41 PM, André Warnier <a...@ice-sa.com> wrote:
> Leon Rosenberg wrote:
>>
>> Pid, Andre
>> thanx.
>> I will try both approaches.
>> I will try the MX Bean first, this just seems to be more elegant ;)
>
> Typical Java thinking..
> Sure, let's pull in another 15 classes..
> Gotta use those GB of RAM for something..
> Why do simple when complicated would do just as well, he ?
> :-)

Well it will actually replace one line of code with another. In fact
the whole code will be shorter (reading of output etc).

>
> While you're at it, here is another variation of the original scheme, much
> more to my own liking :
> String[] cmd = { "/usr/bin/perl", "-e", "print getppid(),\"\\n\";" };
> p = Runtime.getRuntime().exec(cmd);
>
> Same defect as yours though, damn.
>
> Or (from the same jguru post) :
>
> String[] cmd = { "/bin/sh", "-c", "/bin/ps -f | /bin/awk '{print $2,$3}' |
> /bin/grep \"^$$\" | /bin/awk '{print $2}'" };
> p = Runtime.getRuntime().exec(cmd);
>

same fork problem.

> Now that one is not really elegant, but kind of .. macho ! 5 processes in a
> row, with pipes. Woaw.
>
> To get serious again, it /is/ funny that Java does not provide this simple
> function.

I assume that's because not each of the target platforms supports the
concept of a pid ;-)

> And somehow I have a feeling that there may be a catch somewhere when
> dealing with threads under various platforms.

threads? which threads?

> I prefer Konstantin's first suggestion.
> Now the question is : if Tomcat writes it's PID to that file, where does
> Tomcat get it from ?

The problem is, that I don't always run my processes in a tomcat, in
fact most of the time they don't (hence the OT).

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

this looks nice, but won't work without a script (aka start from eclipse).

thank you
regards
Leon

>
>
>>
>> thank you
>> Leon
>>
>> On Wed, Nov 17, 2010 at 10:50 PM, André Warnier <a...@ice-sa.com> wrote:
>>>
>>> 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-unsubscr...@tomcat.apache.org
>>>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

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

Reply via email to