Hi,
I am building a Java Profiler Agent using YourKit Java Profiler API. I am required to list all the Virtual Machines running under the JVM and then attach my Profiler Agent to the listed Virtual Machines. I am not quite sure on how to create an agent that can be attached to the Virtual Machine. The code for listing the Virtual Machine is as follows:

import java.io.IOException;
import java.util.List;
import com.sun.tools.attach.AgentInitializationException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
 
public class VirtualMachineLister
{
	public static void main(String agrs[]) throws AttachNotSupportedException, IOException, AgentLoadException, AgentInitializationException
	{
		List<VirtualMachineDescriptor> vms =  VirtualMachine.list();
		int i = 0;
		for(VirtualMachineDescriptor vmd : vms)
		{
			System.out.println(vmd.displayName());
			System.out.println("The pid is:"+ vmd.id());
			i++;
		}
		System.out.println("The count of the virtual machines is :"+i);
	}
}