Does any one know how do I get the current open windows or process of a local machine using Java?
What I'm trying to do is: list the current open task, windows or process open, like in Windows Taskmanager, but using a multi-platform approach - using only Java if it's possible.
Go to 'Processes' tab. You will see the list of processes running on the system. Bam! Now you will see the entire command line of your java application in the 'command line' column of your java process.
If you want to check the work of java application, run 'ps' command with '-ef' options, that will show you not only the command, time and PID of all the running processes, but also the full listing, which contains necessary information about the file that is being executed and program parameters.
Hold Ctrl+Shift+Esc or right-click on the Windows bar, and choose Start Task Manager. In Windows Task Manager, click on More details. The Processes tab displays all running processes and their current resources usage. To see all processes executed by an individual user, go to the Users tab (1), and expand User (2).
You can use the ps command to view running Java processes on a system also by piping output to grep . OpenJDK, however, has its very own specific process monitor. The Java Virtual Machine Process Status (jps) tool allows you to scan for each running instance of the Java Virtual Machine (JVM) on your system.
This is another approach to parse the the process list from the command "ps -e":
try { String line; Process p = Runtime.getRuntime().exec("ps -e"); 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(); }
If you are using Windows, then you should change the line: "Process p = Runtime.getRun..." etc... (3rd line), for one that looks like this:
Process p = Runtime.getRuntime().exec (System.getenv("windir") +"\\system32\\"+"tasklist.exe");
Hope the info helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With