-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 11/18/2010 12:11 PM, André Warnier wrote:
> Christopher Schultz wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> André,
>>
>> On 11/17/2010 4:50 PM, André Warnier 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.
>>
>> Doesn't that set the "pid" system property to the pid of the shell that
>> launched the JVM?
>>
> Now that you mention it, I think so too.

Something that looks suspiciously like the above, but would probably
work is this:

(exec java -Dpid=$$ program.java)

Since the shell (well, bash anyway) will execute the expression in
parens within a child process and then the 'exec' will replace the
process with another, the $$ magic works.

> Another question is whether it would be possible to "delay" the
> interpretation of the "$$" until such time as when the JVM looks at it.
> Something like : java -Dpid='$$' ...
> (is there a way to tell java to get the value of an environment variable
> when it starts running ? I thought there was something of the kind. But
> maybe that variable is not set then. I am a bit confused now.)

$$ is entirely a shell notion: other processes wouldn't know what $$
meant unless they were specifically programmed to. If the JVM were one
of those things, you'd expect that you could call
System.getCurrentProcessId or something like that. :(

> Maybe we should turn the problem around though.
> If Leon wanted the PID, it was obviously to do something with it later.
> What do you do with a PID ?  Usually, one uses it to send a signal to a
> process.
> And sending a signal to a process, Unix-like, is not likely to be very
> multi-platform in the first place.
> So maybe finding a purely Java-based alternative to do what Leon wants
> to do with the PID would be more productive in the long run ?

+1

You also might want to kill it. In either case, most JVMs are running on
win32 or UNIX-like OSs, and they both support signals.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzlr00ACgkQ9CaO5/Lv0PDBjgCguhUMErvQ+pUyNZ56whBiQC9W
uUMAoKiRheNTWp4xFAPB2IPFhK71Iion
=bReB
-----END PGP SIGNATURE-----

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

Reply via email to