package org.jvnet.winp;

import java.lang.reflect.Field;

/**
 * Represents a Windows process.
 * 
 * @author Kohsuke Kawaguchi
 */
public class WinProcess {
    private final Process proc;
    private final int handle;

    public WinProcess(Process proc) {
        this.proc = proc;

        try {
            Field f = proc.getClass().getDeclaredField("handle");
            f.setAccessible(true);
            handle = ((Number)f.get(proc)).intValue();
        } catch (NoSuchFieldException e) {
            throw new NotWindowsException(e);
        } catch (IllegalAccessException e) {
            throw new NotWindowsException(e);
        }
    }

    public void killRecursively() {
        int pid = Native.getProcessId(handle);
        Native.kill(pid,true);
    }
}

@@ -183,52 +183,84 @@
 nal 
-Process proc;%0D%0A    private final int handle;
+int pid;%0D%0A%0D%0A    public WinProcess(int pid) %7B%0D%0A        this.pid = pid;%0D%0A    %7D
 %0D%0A%0D%0A
@@ -302,37 +302,8 @@
  %7B%0D%0A
-        this.proc = proc;%0D%0A%0D%0A
     
@@ -428,16 +428,20 @@
         
+int 
 handle =
@@ -472,24 +472,72 @@
 ntValue();%0D%0A
+            pid = Native.getProcessId(handle);%0D%0A
         %7D ca
@@ -720,32 +720,32 @@
     %7D%0D%0A    %7D%0D%0A%0D%0A
+
     public void 
@@ -769,56 +769,8 @@
  %7B%0D%0A
-        int pid = Native.getProcessId(handle);%0D%0A
     

allow construction from PID