Is it possible to change the cmdline of a running process (to more easily identify it in top, for example)?
Solution 1
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:
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
Solution 2
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.
Solution 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.
Solution 4
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
Solution 5
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.
Related videos on Youtube
Josh
I am Josh Gitlin, CTO and co-founder of Digital Fruition a software as a service eCommerce company. Currently serving as Principal DevOps Engineer at Pinnacle 21, and hacking away at Cinc Server, the free-as-in-beer rebranded distribution of Chef Server.
Updated on September 17, 2022Comments
-
Josh over 1 year
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 havetop
open all day long. The issue is, the cmdline ofvmware-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?
-
Josh over 13 yearsTrue, 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! -
mfinni over 13 yearsYeah, script it from the other side.
-
Josh over 13 yearsThis 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!