1

I run a number of linux servers with VMware Server 2. When their response time is not so hot or the load average goes up, I open up top to see what's going on, or for our production servers I have top open all day long. The issue is, the cmdline of vmware-vmx processes is really long, for example:

/usr/lib/vmware/bin/vmware-vmx -# product=2;name=VMware Server;version=2.0.2;buildnumber=203138;licensename=VMware GSX Server for Linux;licenseversion=3.0 build-203138; -@ pipe=/tmp/vmhsdaemon-0/vmxaf9a31943e9065f0;readyEvent=55 /var/lib/vmware/Virtual Machines/Kyle.vmwarevm/Kyle.vmx

So in top all I see is:

 4135 root      20   0  593m 324m 289m S   21  4.2   3038:04 /usr/lib/vmware/bin/vmware-vmx -# product=2;name=VMware Server;
 4106 root      10 -10  997m 399m 346m S    9  5.1   1135:25 /usr/lib/vmware/bin/vmware-vmx -# product=2;name=VMware Server;
 4074 root      20   0  833m 110m  97m S    2  1.4 722:19.38 /usr/lib/vmware/bin/vmware-vmx -# product=2;name=VMware Server;

In VMWare Server 1, each VM would run as it's own user so I could easily tell which one was which. Not so with VMWare Server 2. In lieu of buying a really wide monitor or a triple monitor setup, is there any way I can alter the cmdline of these running processes so I can easily identify which one's which? I know the processes can alter the cmdline of themselves... and I can read (but not write to) /proc/nnn/cmdline...

Is there any way (as root) to alter the cmdline of a running process?

7 Answers 7

4

Although probably noone is going to use VMWare Server any more, this problem would arise with other processes as well. You really should look at htop instead, it allows for side-scrolling to read the entire command line and displays process trees:

http://htop.sourceforge.net/htop-1.0-screenshot.png

As for your question, changing the command line of a process which is runnnig already is likely to be possible only by overwriting data at the memory address of its ARGV[0]. To my knowledge, no tool is yet available which just would do changecmdline 4652 "foo process". Further discussion: http://stupefydeveloper.blogspot.de/2008/10/linux-change-process-name.html

3

How about the following:

watch 'ps -eo pid,pcpu,args | grep vmware'

Watch will run the command every 2 seconds. pcpu is cpu percentage.

1
  • This is pretty close. I could probably combine this with sed to show exactly what I want. If nobody else provides the exact answer I'm looking for, I'll assume it can't be done and will probably accept this one. Thanks!
    – Josh
    Sep 25, 2010 at 15:14
3

This is indeed an annoying problem.

The real solution is posted here:

http://blog.angulosolido.pt/2012/01/vmware-2-long-process-names-and-top.html

The script is NOT pretty but it works.

2

Short answer, I don't think it is possible without recompiling the kernel. I've checked top and it's definitely pulling it from /proc:
strace top -c 2>&1 | grep "proc"
open("/proc/6501/stat", O_RDONLY) = 4
open("/proc/6501/statm", O_RDONLY) = 4
open("/proc/6501/cmdline", O_RDONLY) = 4

As you say, /proc/pid/cmdline is not writeable by root. Have you considered running them with a wrapper program? eg. bash script ./vmware that just executes
/usr/lib/vmware/bin/vmware-vmx -# product=2;name=VMware Server;version=2.0.2;buildnumber=203138;licensename=VMware GSX Server for Linux;licenseversion=3.0 build-203138; -@ pipe=/tmp/vmhsdaemon-0/vmxaf9a31943e9065f0;readyEvent=55 $1"

It's worth noting that top only truncates when it's out of space. Why not open top, hit f and remove any fields you're not using. You might just find it leaves enough space for the entire cmdline

0
1

Not a direct answer to your question, but perhaps an answer to your problem:

  1. Use LSOF to find out which PIDs are using which VMDKs
  2. Use ps and grep for those PIDs

This could be easily scripted, I don't have a Linux console opened right now though. Exercise left for the reader.

2
  • True, I could script that. I'm basically using ps and grep right now -- finding the top orocess, switching screens, ps awwwx | grep $pid, and this gives me the VMX name, it's just tedious!
    – Josh
    Sep 24, 2010 at 13:31
  • Yeah, script it from the other side.
    – mfinni
    Sep 24, 2010 at 13:34
1
#!/bin/bash

DELAY=2
DIRNAME=virtual

while true; do
    clear; ps -eo pid,pcpu,args | grep vmx|grep $DIRNAME  |awk '{ print $1 " " $2 " " $NF}'| sort -rn -k 2; sleep $DELAY;
done
1

Try this:

#!/bin/sh
A=`ps -e -o pid,cmd| grep vmware-vmx | grep -v match | awk 'BEGIN {print "{" } {gsub(/^.*\//, "", $NF); print "if (match($0, / *" $1 " /)) { sub(\"vmware-vmx          \",\"" "%-20s" "\",$0); printf($0,\"" $NF "\"); print \"\";} else "} END {print "print $0 }"}'`
top | awk "$A"

The script works as a filter to TOP output and replaces "vmware-vmx" with VM name. It assumes .vmx file is no more than 20 chars. This is because you have to preserve the line size generated by top.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .