为Java子进程(ProcessBuilder)指定一个名称。

huangapple 未分类评论46阅读模式
英文:

Assign a name to a Java Sub Process (ProcessBuilder)

问题

我想为由Java应用程序通过*ProcessBuilder()*在Java中调用的子进程分配一个名称。

ProcessBuilder builder = new ProcessBuilder();

builder.environment().put("CLASSPATH", ""); // 取消设置类路径

strategy.loadEnvVariables(builder.environment()); // 将环境变量设置到构建器进程中

String[] invokeCommands = strategy.getInvokeCommands(); // 获取启动子进程所需的命令

process = builder.command(invokeCommands).start();

上述代码运行良好。但我想为该子进程分配一个名称,以便在“ps ux”命令中看到。

例如

lsesv-s  27090  0.0  0.0 290168 25564 ?        S    10:43   0:00 /x02/lsesv-s/postgres/bin/postgres -D /x02/lsesv-s/postgres/datamhv

这是由我的Java应用程序调用的示例子进程,并且它会将命令参数作为默认名称传递。但我需要它能够通过我传递给“ProcessBuilder()”对象的名称可见,或者有任何其他方法可以实现可见性?

英文:

I want to assign a name for a sub-process that is invoking by a java application via the ProcessBuilder() in Java.

ProcessBuilder builder = new ProcessBuilder();

builder.environment().put("CLASSPATH", ""); // Unsetting classpaths

strategy.loadEnvVariables(builder.environment());  // set env variables to builder process

String[] invokeCommands = strategy.getInvokeCommands(); // get commands that need to start the sub process

process = builder.command(invokeCommands).start();

The above code is working fine. But I want to assign a name to that subprocess to see in "ps ux" command by the given name.

E.g

lsesv-s  27090  0.0  0.0 290168 25564 ?        S    10:43   0:00 /x02/lsesv-s/postgres/bin/postgres -D /x02/lsesv-s/postgres/datamhv

This is a sample subprocess that invoked by my java application and it gets passed commands arguments as the default name. But I need it to be visible by a name which I passed to the "ProcessBuilder()" object or any workaround to get visible?

huangapple
  • 本文由 发表于 2020年7月25日 18:25:08
  • 转载请务必保留本文链接:https://java.coder-hub.com/63087201.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定