Figure Out Which Java Process Is you want in Windows Task Manager is difficult task. In this tutorial, we see how to solve this problem and change java process name to a unique name.
Windows Task Manager – Figure Out The Java Process You Want
It is a frustrating situation: You invoke the same Java program several times or invoke several java programs. After several minutes, you decide you want to kill one of the Java programs you invoke. It should be a straightforward task – You open the Windows Task Manager and search the java program you want to kill. However, when you do not find the Java program names, Instead you see several java.exe processes. How to figure out which Java process is which? Which one is the java program you want to kill? You do not have a clue.
Solution To Figure Out Which Java Process Is Which
Windows Task Manager displays the image name of the process. Therefore, Windows Task Manager displays java.exe for each java program we invoke regardless of the java program class.
If you can modify the image name of the java.exe to a unique name for each java program you want to execute, you would immediately figure out which java process you want in Windows Task Manager. Let’s use this observation in the following solution:
Copy the java.exe to a unique name (For example, my-name.exe) for each Java program you want to execute. Next, run my-name.exe instead of the original java.exe. We can invoke it, as usual, to invoke any java program since this my-name.exe file is a copy of java.exe. Yet, When we open Windows Task Manager, we can instantly figure out which java process is which because we will see several processes of different program files instead of several processed of java.exe
Script To Change The Java Process Name
The following batch script automates the above solution. Create a new file named
java-by-name.bat in the java directory:
set JAVA_HOME=%~dp0 set JAVA_NAME=%1.exe copy "%JAVA_HOME%java.exe" "%JAVA_HOME%%JAVA_NAME%" set args=%* set args=%args:* =% "%JAVA_HOME%%JAVA_NAME%" %args%
What the script do?
%~dp0 is the directory of the batch script we invoked. Since the file is located reside alongside the java.exe –
JAVA_HOME will get the value of the java installation directory.
set JAVA_NAME=%1.exe copy "%JAVA_HOME%java.exe" "%JAVA_HOME%%JAVA_NAME%"
The first argument to the script of the script is the name copy of java.exe we want. We copy java.exe to this name.
set args=%* set args=%args:* =% "%JAVA_HOME%%JAVA_NAME%" %args%
Finally, we execute the copy of the java.exe with the rest of the given arguments of the script.
How To Use?
Now, Let’s see how we can use this above batch to differentiate between the java programs.
Suppose you want to run the following commands:
Command A – Invoke with java
java my-program.class arg1 arg2 arg3 arg4
Command B – Invoke with java-by-name
java-by-name my-program my-program.class arg1 arg2 arg3 arg4
The above commands: command A (
java) and command B (
java-by-name), will execute the same java program with the same arguments. Yet, when we open Windows Task Manager, we see that the image name of the process of command A is
java.exe while the image name of the process of command B is
Now, you should provide a unique name for command B for each java program you run. Then, you can undoubtedly figure out which java process you want in the Windows Task Manager.