In an integrated development environment, because of the high cost of hardware, several developers are often required to share a single hardware device.
A typical application is: two or three people share a device, Linux Server, and then use VMware to install their own debugging run environment, we share a user name (usually not root) landing. Due to the bottleneck of hardware performance bottlenecks, only one virtual machine can be run at the same time (theoretically, it is possible to run multiple virtual machines simultaneously, but the speed is slow, the performance cannot keep up with the actual application). When the current user logs on to use the hardware device, need to kill other colleagues left over the process (theoretically should be the initiator of the process to clean up, but may often be forgotten, similar to the toilet forgot to flush), when the current user needs to use the command "Ps-ef|grep VMware" to view the legacy process number, Then use the command "Kill-9 ProcessID" to kill. Often do so, very cumbersome trouble, so I wrote a tool, tested a bit, very good, and specifically share.
Source code is as follows
#!/bin/ksh
if [[$ = =]]
then
print "KO username, please input username!"
Exit 1
fi
username=$1
print "\nbefore kill:\n"
ps-ef|grep vmware
print \nkilling ... "
Echo > Tmp.txt
ps-ef|grep "^${username}.*vmware" |grep-v Grep|awk ' {print $} ' >>. tmp.txt while
read Li Ne
do
if [[${line}!=]]; Then
kill-9 ${line}
fi do
<.tmp.txt
rm. Tmp.txt Sleep
2
print "\nafter kill:\n"
ps-ef|grep VMware
exit 0
Run results
Extended
If you want to kill another process associated with a user (with a keyword), just replace the VMware keyword in the script, and the students who need it can change their own.