1、脚本名称:killProcess.sh
功能:检测某程序是否运行,若运行则kill掉,否则退出。(这里检测下载程序curl的个数)
内容:
#!/bin/bash
function killProcess()
{
processName=$1
processNum=$(ps aux|grep "${processName}"|grep -v "grep"|wc -l 2>/dev/null)
if [ ${processNum} -eq 0 ]
then
printf "${processName} doesn't run./n"
else
killall -9 ${processName}
printf "${processName} is killed./n"
fi
}
killProcess curl
printf "Kill OK./n"
2、运行脚本:
chmod 755 killProcess.sh
./killProcess.sh
或者bash killProcess.sh