On 3/1/19 2:31 AM, Shawn Anastasio wrote: > Hello all, > > I'm currently writing a C program that uses the libvirt API and I need a > way to obtain the pid of a given domain's QEMU process. > > Specifically, I'm writing an ivshmem server that uses SO_PEERCRED to get > the pid of clients that connect to it, and I would like to use that pid > to look up the domain in libvirt to determine the proper domain ID to > return to the client. > > As far as I can tell, libvirt doesn't expose this information in an easy > to access manner. Of course it is possible to call `ps` and grep for the > information I'm looking for, but I was hoping for a cleaner solution. > > If anybody knows how to do this, advice would be greatly appreciated. There isn't an API for that as we don't want users to fiddle with qemu behid its back. Anyway, apart from ps there might be a solution. Libvirt of course know the PID and stores it - in the status XML. This is a file that libvirt uses to store runtime information for the domain in case the daemon restarts. It's located under /var/run/libvirt/qemu/$domain.xml. But you'll need root priviledges to read it. Also, it is very wise to follow the comment at the beginning of the file and not modify it ;-) And just like with any libvirt internals, we make no guarantees they won't change in the long run. Michal _______________________________________________ libvirt-users mailing list libvirt-users@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvirt-users