-
-
Save bigdragon1977/1895bfc78c4d7911cd2536af1a7e7a1b to your computer and use it in GitHub Desktop.
attach to JVM use java attach API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sun.tools.attach.VirtualMachine; | |
import com.sun.tools.attach.VirtualMachineDescriptor; | |
import java.util.List; | |
public class ListVM{ | |
public static void main(String[] args){ | |
List<VirtualMachineDescriptor> vmList = VirtualMachine.list(); | |
for(VirtualMachineDescriptor vm : vmList){ | |
System.out.println("name: " + vm.displayName() + " id :" + vm.id()); | |
try{ | |
VirtualMachine vm0 = VirtualMachine.attach(vm.id()); | |
// load agent, agnet class's agentmain will be invoked. | |
vm0.loadAgent("/root/tmp/ChinaAgent.jar"); | |
System.out.println("Load agent done."); | |
vm0.detach(); | |
}catch(Exception e) { | |
System.out.println("exception : " + e.getMessage()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment