查看和杀死进程

目的

ubuntu 系统中,杀死含有名称/pid/关键字 的进程。

查看待杀进程 st

cat /usr/bin/st

显示如下:

echo -------------------------- netstat -anp ------------------------------------
echo 
echo Proto Recv-Q Send-Q Local Address --------- Foreign Address ------- State ----- PID/Program name
echo
netstat -anp | grep $1 | grep -v grep | grep -v unix 
echo
echo -------------------------- ps -aux ------------------------------------------
echo
echo USER ----- PID %CPU %MEM -- VSZ - RSS -- TTY STAT - START - TIME COMMAND
echo
ps -aux | grep $1 | grep -v grep | grep -v unix 
echo
echo ------------------------- over ----------------------------------------------

杀死进程 kt

cat /usr/bin/kt

显示如下:

echo kill task start...
echo $0
echo $1
threadpid=1
while [ $threadpid -ge 1 ]
do
threadpid=`netstat -anp|grep $1 | grep -v grep | grep -v root | grep -v unix | sed -n '1p' | awk '{printf $7}'|cut -d/ -f1`
echo $threadpid
sudo kill -9 $threadpid
done

echo kill netstat over...

threadpid=1
while [ $threadpid -ge 1 ]
do
threadpid=`ps -aux | grep $1 | grep -v grep | grep -v root | grep -v unix | sed -n '1p' | awk '{printf $2}' | cut -d/ -f1`
echo $threadpid
sudo kill -9 $threadpid
done

echo kill task end...

你可能感兴趣的:(C)