I need to recreate the functionalities of the jps tool programmatically. I need to find out all Java running processes along with their id so I can attach to that process (similar to what JConsole does).
I thought the VirtualMachine API would help, but did not get expected result when I run the following
public class ProcessList {
public static void main(String[] args){
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for(VirtualMachineDescriptor vm : vms){
System.out.println (vm.id());
}
}
}
When I run the code above, it returns just one ID, but when I run jps on the same machine I see several other processes.