Aug 19, 2013

KVM: How to find a guest VM's process ID (PID)

There are two ways to find VCPUs' PID.

Suppose the testing VM is named GUEST_X and it has 4 VCPUs.

Method A: 
If you are using libvirt to manage VMs.
You can type:

sudo grep pid /var/run/libvirt/qemu/GUEST_X.xml 

Then, you will see VCPUs' PID like this:
<domstatus state='running' reason='booted' pid='6556' >
<vcpu pid='6558'/ >
<vcpu pid='6559'/ >
<vcpu pid='6560'/ >
<vcpu pid='6561'/ >

Method B:
Alternatively, you can find the guest's main PID in user space by typing this:
ps aux | grep GUEST_X 
You will see something like this:
root     6556 0.1  0.0 136560  3472 ?        Sl   20:49   0:02 /usr/bin/kvm ...GUEST_X....(a long list of parameters)
Then, you can use ls to check the directories in
/proc/6556/task/
You will see directories like this
/proc/6556/task/6556/
/proc/6556/task/6558/
/proc/6556/task/6559/
/proc/6556/task/6560/
/proc/6556/task/6561/
where 6558~6561 are PIDs of this guest's VCPUs.


Ending picture today:
Niagara Falls view [courtesy of my dear wife - Claire Huang]

No comments:

Post a Comment