分享一个通过进程名杀死进程的脚本,不需要找到进程号一一杀死,大大提高了工作效率
使用方法: kproc 程序1 程序2 ...
脚本文件kproc
#!/bin/sh PRGN=`basename $0` TMPF="/var/tmp/$PRGN.$$" quit () { rm -f $TMPF exit $1 } #===============# # MAIN Entrance # #===============# if [ $# -lt 1 ]; then echo "Usage: $PRGN {process_name}" quit 1 fi uid=`id -u` if [ $uid -eq 0 ]; then echo "Superuser cannot use this program !" quit 1 fi while [ $# -ge 1 ]; do ps -f -u $uid | grep -w $1 | egrep -v "grep|kproc|vi|pts" > $TMPF cnt=`cat $TMPF | wc -l` while [ $cnt -gt 0 ]; do line=`sed -n "${cnt}p" $TMPF` pid=`echo $line | cut -d " " -f2` kill -16 $pid echo stop $1 --- $pid cnt=`expr $cnt - 1` done shift done quit 0