How to change / assign java.jar process name

I am running Minecraft under Linux, which includes launching the .jar executable. This means that it appears as “java” under ps, not “minecraft”. I would like to give it the name of the process "minecraft".

Looking around, I found the following tip for naming a process through bash:

How to change the name of a Java application process?

exec -a goodname java ... 

I usually run:

 java -cp ~/Games/Minecraft/Minecraft.jar net.minecraft.LauncherFrame 

So try making a bash script:

 #!/bin/bash exec -a minecraft java -cp ~/Games/Minecraft/Minecraft.jar net.minecraft.LauncherFrame 

But when I run this, it still appears as "java" under the ps command.

What am I doing wrong?

+7
source share
1 answer

This works for me. I did not test using java, but I tested using sleep :

 victor@vz :~$ exec -a minecraft sleep 1m & [1] 3858 victor@vz :~$ ps x | grep mine 3858 pts/2 S 0:00 minecraft 1m 3860 pts/2 S+ 0:00 grep --color=auto mine victor@vz :~$ 

However, this is apparently just a cosmetic change, as far as I can tell from the documentation:

victor @vz: ~ $ help exec exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...] Replace the shell with this command.

 Execute COMMAND, replacing this shell with the specified program. ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified, any redirections take effect in the current shell. Options: -a name pass NAME as the zeroth argument to COMMAND 

Regarding the OP comment on this answer: I just tested it on a remote machine using java:

 victorz@exa :~$ javac test.java # spits out an Administrator.class file among others victorz@exa :~$ exec -a minecraft java Administrator & [1] 13142 victorz@exa :~$ ps x | grep mine 13142 pts/1 Sl 0:00 minecraft Administrator 13161 pts/1 S+ 0:00 grep --color=auto mine victorz@exa :~$ 

Perhaps you are not using switch x to ps ? I don't get a match if I don't use the x switch.

+2
source

All Articles