Article View: borland.public.jbuilder.java.language
Article #7538Re: Get program id from java
From: John McGrath TeamB
Date: Tue, 05 Jun 2001 09:25
Date: Tue, 05 Jun 2001 09:25
35 lines
2446 bytes
2446 bytes
On Tue, 05 Jun 2001 16:03:59 +0800, Russell wrote:
> I can see PID for a process , but how i am going to get PID
> value??? I try to read value without any successful ,belows
> is the code.
There are techniques that you can use to get at just about anything in
Java, but be aware that doing this would depend on the implementation,
which could change. The class of the Process object that you saw was
actually a subclass of Process, since process is abstract. It may be
that a future version of the Java platform you are using will change
that class, or return an entirely different subclass of Process. It is
even possible that the current implementation of Runtime exec() may
return a different subclass of Process depending on some unknown
factors.
In other words, you would be giving up the assurances of portability
that you currently have if you delve into the innards of code that is
implementation dependant. If you do that sort of thing, you should
write *very* defensive code, and plan for the contingency that it will
fail.
That said, if you are *sure* that you want to do this sort of thing,
you should be able to use the Reflection API to get at the PID field.
If the field is not normally accessible, it is possible to override
the accessibility using the setAccessible() method.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<MPG.15866f22a70b49a598a264@forums.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3B1C5D8E.36A4A8C4@cesmainternational.com> <MPG.158654718aa35dbb98a262@forums.borland.com> <3B1C926F.8E6ADE24@cesmainternational.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,12a44754146f6396 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-06-05 02:43:43 PST From: John McGrath [TeamB] <ng-b@JPMcGrath.net> Newsgroups: borland.public.jbuilder.java.language Subject: Re: Get program id from java Date: Tue, 5 Jun 2001 05:25:49 -0400 Message-ID: <MPG.15866f22a70b49a598a264@forums.borland.com> References: <3B1C5D8E.36A4A8C4@cesmainternational.com> <MPG.158654718aa35dbb98a262@forums.borland.com> <3B1C926F.8E6ADE24@cesmainternational.com> X-Newsreader: MicroPlanet Gravity v2.30 NNTP-Posting-Host: 209.92.40.60 X-Trace: dnews 991733148 209.92.40.60 (5 Jun 2001 02:25:48 -0700) Lines: 35 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!ihug.co.nz!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews