我希望能够做这样的事情:
Process p = getRunningProcess(pid)
如果有办法,该过程的创建方式是否重要(使用java,使用python,从shell等)?
最佳答案
可以从Java应用程序附加到另一个JVM进程(例如,能够to monitor what's going on and potentially detect problems before they happen
)。您可以使用Attach API做到这一点。对附加到非JVM进程了解不多。
String name = ...
List vms = VirtualMachine.list();
for (VirtualMachineDescriptor vmd: vms) {
if (vmd.displayName().equals(name)) {
VirtualMachine vm = VirtualMachine.attach(vmd.id());
String agent = ...
vm.loadAgent(agent);
// ...
}
}