New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
KVM VM ID from PID
SimpleNode
Member
I really hate to ask this herre, as I don't want to be a shovenose :P, but...
I'm working on a little script and I can't seem to find a way to get a KVM VM's ID from it's process ID, or vice versa?
I've tried googling the issue, and I can't seem to find anything on it. Possibly one of you know?
Comments
Um,
you could just do
ps aux | grep pid
make sure to put the first char in [ ] to exclude grep
Then just parse out the -name variable?
I tried that before but...
It seems like it's not working for the PID that I've been testing this with, but it's working with another KVM process... odd. It outputs the correct data for the other processes, just not this one.
And I'm sure this one is KVM.
rough guess
top -n 1 | awk '{print $1,$12}' | grep qemu-kvm | awk '{print $1}' > /tmp/list1
while read list
do
echo $list
ps aux | grep $list | grep -o kvm[0-9][0-9][0-9]
done </tmp/list1
That should work and give you an output like
33331
kvm123
44442
kvm125
That is just out of my head though, not tested.
pre tags are broken for some reason: http://pastie.org/private/9rsfop6gur6obr0tvacr2w
view that as raw, for some reason it is causing stupid highlighting and bolding etc.
man the tags are messed up on this forum, maybe that is the next post haha?
This will return PID and name:
ps awx | grep qemu | grep -v grep | sed 's/\s*\([0-9]*\).*-name \(\w*\) .*/\1 \2/'
hmm. This is extremely odd
Alright, I've got a thread ID. How do I get a process ID?
So iotop is giving me a TID - 11308, however even ps -el doesn display it... odd.
nvm, got it. @Infinity can close this now ;P
ps -eL
to see thread ids@t3k9 Already did that thanks. I was tripped up by the fact that while 99% of it appears to be in numerical order..... it's not.
With this I get:
28648 kvm111
What is the number next to the id? Is there a way I can see how much memory each individual kvm vps is using?
Okay thanks, I overlooked that. How about my other question. Is there a way I can see how much memory each individual kvm vps is using?
@colustro
Have you tried using the libvirt API? You can gather the memory from that, as well as finding out the PID similar to how SimpleNode solved it.