Is there any way to get / connect / attach an already running process using java?

I want to do something like this:

Process p = getRunningProcess(pid) 

If there is a way, does it matter how the process was created (using java, using python, from the shell, etc.)?

+6
source share
1 answer

You can connect to another JVM process from a Java application (for example, to be able to monitor what going on and potentially detect problems before they happen ). You can do this using the Attach API . I don’t know much about connecting to processes other than the 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); // ... } } 
+5
source

Source: https://habr.com/ru/post/902306/


All Articles