Question: I have this so far:

```
public static void main(String[] args) {

    try {
        String line;
        Process p = Runtime.getRuntime().exec(
                System.getenv("windir") + "\\system32\\" + "tasklist.exe");

        BufferedReader input = new BufferedReader(new InputStreamReader(
                p.getInputStream()));

        while ((line = input.readLine()) != null) {
            System.out.println(line); // <-- Parse data here.
        }
        input.close();
    } catch (Exception err) {
        err.printStackTrace();
    }

    Scanner killer = new Scanner(System.in);

    int tokill;

    System.out.println("Enter PID to be killed: ");

    tokill = killer.nextInt();

}

```

}

I want to be able to kill a process based on the PID a user enters. How can I do this? (Only needs to work on Windows). \*NB: Must be able to kill any process, inc. SYSTEM processes, so I'm guessing a -F flag will be needed if using taskkill.exe to do this?

So if I had 

```
Runtime.getRuntime().exec("taskkill /F /PID 827");

```

how can I replace "827" with my tokill variable?

Answer: 
Simply build the string to kill the process:

```
String cmd = "taskkill /F /PID " + tokill;
Runtime.getRuntime().exec(cmd);

```
```
String cmd = "taskkill /F /T /PID " + tokill;
Runtime.getRuntime().exec(cmd);

```

Use taskkill if you are on Windows.

You may want to use the /T option to kill all spawned child processes.