Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change/assign process name of java .jar

I'm running Minecraft under Linux, which involves running an executable .jar file. This means it shows up as "java" under ps, rather than "minecraft". I would like to assign it the process name "minecraft".

Looking around, I found the following tip for assigning a process name via bash:

how to change the name of a Java application process?

exec -a goodname java ...

I usually run with:

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

So tried make a bash script:

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

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

What am I doing wrong?

like image 637
emacsomancer Avatar asked Jan 10 '11 18:01

emacsomancer


1 Answers

It works for me. I haven't tested with java, but I tested with 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 seems to be merely a cosmetic change as far as I can tell by the documentation:

victor@vz:~$ help exec exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...] Replace the shell with the given 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

In reference to OP's comment to this answer: I just tested it on a remote machine with java as well:

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:~$ 

Maybe you are not using the x switch to ps? I get no match unless I use the x switch.

like image 122
Victor Zamanian Avatar answered Oct 13 '22 01:10

Victor Zamanian