在 2012年4月11日 下午7:22,Richard W.M. Jones <rjones@xxxxxxxxxx> 写道: > On Wed, Apr 11, 2012 at 12:01:55PM +0100, Daniel P. Berrange wrote: >> On Wed, Apr 11, 2012 at 06:41:34PM +0800, Zhihua Che wrote: >> > BTW, Does libvirt supply any function which can return the process >> > identifier of the domain? >> >> No, we don't consider the PID of the QEMU process to be part of the >> public API, since that is a hypervisor specific implementation detail. >> Why do you want to know that ? Maybe there is some API you can use >> to get do the same thing > > I agree with Dan that you're probably doing it for the wrong reasons > and shouldn't need to know the PID. Yes, I know this is not reasonable, I just wanna try my luck.:( I just wonder if I could distinguish the VM process and non-VM process. > > Nevertheless, it's pretty simple to map a running domain name to a > qemu PID, by parsing the '-name' parameter from the process list. > eg the following works for simple names (no spaces, metachars etc): > > $ sudo virsh list --all > Id Name State > ---------------------------------- > 2 builder-rhel6 running > > $ ps ax | grep '[-]name builder-rhel6' | awk '{print $1}' > 2311 > > Rich. > Yeah, I tried a similar way and just worried what if someone faked a VM process.