Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of current open windows/process with Java?

Tags:

java

process

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.

like image 353
Rodrigo Amaya Avatar asked Sep 10 '08 16:09

Rodrigo Amaya


People also ask

How do I list all Java processes in Windows?

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.

How do you check if a process is running in Windows using Java?

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.

How do I see current processes in Windows?

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).

How do I see all the processes running a Java process in terminal?

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.


1 Answers

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!

like image 76
Rodrigo Amaya Avatar answered Sep 24 '22 10:09

Rodrigo Amaya