如何更改/分配java .jar的进程名称

时间:2021-12-18 16:25:26

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

我在Linux下运行Minecraft,它涉及运行可执行的.jar文件。这意味着它在ps下显示为“java”,而不是“minecraft”。我想为它分配进程名称“minecraft”。

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

环顾四周,我发现以下提示通过bash分配进程名称:

how to change the name of a Java application process?

如何更改Java应用程序进程的名称?

exec -a goodname java ...

I usually run with:

我经常跑:

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

So tried make a bash script:

所以尝试制作一个bash脚本:

#!/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.

但是当我运行它时,它仍然在ps命令下显示为“java”。

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


2  

It works for me. I haven't tested with java, but I tested with sleep:

这个对我有用。我没有用java测试,但我测试了睡眠:

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.

victor @ vz:〜$ help exec exec:exec [-cl] [-a name] [command [arguments ...]] [redirection ...]用给定的命令替换shell。

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:

参考OP对这个答案的评论:我刚刚在带有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:~$ 

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

也许你没有使用x开关来ps?除非我使用x开关,否则我得不到匹配。

#1


2  

It works for me. I haven't tested with java, but I tested with sleep:

这个对我有用。我没有用java测试,但我测试了睡眠:

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.

victor @ vz:〜$ help exec exec:exec [-cl] [-a name] [command [arguments ...]] [redirection ...]用给定的命令替换shell。

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:

参考OP对这个答案的评论:我刚刚在带有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:~$ 

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

也许你没有使用x开关来ps?除非我使用x开关,否则我得不到匹配。