Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


KVM VM ID from PID
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.

KVM VM ID from PID

SimpleNodeSimpleNode Member
edited March 2013 in Help

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.

  • AnthonySmithAnthonySmith Member, Patron Provider
    edited March 2013

    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.

  • AnthonySmithAnthonySmith Member, Patron Provider
    edited March 2013

    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.

  • AnthonySmithAnthonySmith Member, Patron Provider

    man the tags are messed up on this forum, maybe that is the next post haha?

  • t3k9t3k9 Member

    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

  • t3k9t3k9 Member

    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.

  • t3k9 said: This will return PID and name: ps awx | grep qemu | grep -v grep | sed 's/\s([0-9]).-name (\w) .*/\1 \2/'

    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?

  • Awmusic12635Awmusic12635 Member, Host Rep
    edited August 2014

    conlustro said: What is the number next to the id?

    t3k9 said: This will return PID and name

  • 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?

    Thanked by 1Foul
  • KihiKihi Member

    @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.

Sign In or Register to comment.