Preface
A node from http://bugs.sun.com/view_bug.do?bug_id=4244896
How
On Linux:
- if(process.getClass().getName().equals("java.lang.UNIXProcess")) {
- /* get the PID on unix/linux systems */
- try {
- Field f = process.getClass().getDeclaredField("pid");
- f.setAccessible(true);
- pid = f.getInt(p);
- } catch (Throwable e) {
- }
- }
Download the jna.jar on Suns JNA Site:
- if (process.getClass().getName().equals("java.lang.Win32Process") ||
- process.getClass().getName().equals("java.lang.ProcessImpl")) {
- /* determine the pid on windows plattforms */
- try {
- Field f = p.getClass().getDeclaredField("handle");
- f.setAccessible(true);
- long handl = f.getLong(p);
- Kernel32 kernel = Kernel32.INSTANCE;
- W32API.HANDLE handle = new W32API.HANDLE();
- handle.setPointer(Pointer.createConstant(handl));
- pid = kernel.GetProcessId(handle);
- } catch (Throwable e) {
- }
- }
Supplement
* Stackoferflow - How to execute a interactive shell script using java Runtime?
沒有留言:
張貼留言