使用awk
#!/bin/bash
#echo "$1"
pid=`ps -ef | grep loop28 | grep -v grep | grep -v bash | awk '{print $2}'`
echo "$pid"
if [ -n "$pid" ]
then
echo "kill -9 pid:$pid"
kill -9 $pid
fi
用列来指定
#!/bin/bash
echo "closing app"
# name为要杀死的进程名称
name="loop28"
column=8
i=0
# 每8个算一行 第2列就是pid
for item in $(ps -ef|grep ${name})
do
if [ ${i} -eq 1 ]
then
kill ${item}
echo "process pid:"${item}
fi
let i++
if [ ${i} -eq ${column} ]
then
i=0
fi
done