Find the PID and Names of Virtual Machines on Centos 7
On my Centos 7 system, I wanted to find out which VM was taking up a large amount of the processor:
top - 14:43:15 up 3 days, 7:49, 2 users, load average: 1.66, 1.79, 1.99 Tasks: 442 total, 1 running, 220 sleeping, 0 stopped, 0 zombie %Cpu(s): 15.3 us, 6.8 sy, 0.0 ni, 77.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 65953896 total, 4408848 free, 44640236 used, 16904812 buff/cache KiB Swap: 33030140 total, 23595476 free, 9434664 used. 19506000 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 8228 qemu 20 0 32.2g 31.2g 5904 S 458.8 49.6 8500:27 qemu-kvm 7258 root 20 0 1439420 86100 32900 S 11.8 0.1 2:23.18 virt-manager 8290 qemu 20 0 2669460 903592 6000 S 11.8 1.4 789:14.52 qemu-kvm 8143 qemu 20 0 4997832 3.6g 6460 S 5.9 5.7 1586:45 qemu-kvm 12445 root 20 0 162260 4688 3808 R 5.9 0.0 0:00.03 top 1 root 20 0 195384 6616 4616 S 0.0 0.0 0:16.87 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.91 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kb 7 root 20 0 0 0 0 I 0.0 0.0 1:17.94 kworker/u48:0-m 9 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq 10 root 20 0 0 0 0 S 0.0 0.0 1:50.94 ksoftirqd/0 11 root 20 0 0 0 0 I 0.0 0.0 2:54.42 rcu_sched 12 root rt 0 0 0 0 S 0.0 0.0 0:01.92 migration/0 14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1
I created a script
#!/bin/bash ps awx | grep qemu | grep -v grep | sed 's/\s*\([0-9]*\).*-name \(\w*\) .*/\1 \2/'
The output was as follows:
7054 NAS1 8108 MX1 8143 mail8 8187 Server2 8228 Server1 8290 NAS2