1.进程的批量kill
ps -ef |grep -v "root"|grep "keyword"|awk '{print $2}'|xargs kill -9
2.进程并行化之软件
软件一:ParaFly:
https://github.com/ParaFly/ParaFly
示例,用服务器一半CPU运行程序:
echo "ls ~
df
ls -lh ~/bin" > bashfile
cpus=$( ls -d /sys/devices/system/cpu/cpu[[:digit:]]* | wc -w |awk '{print $1/2}')
ParaFly -c bashfile -CPU $cpus
# Usage: ParaFly (opts)
# Required:
# -c <str> :filename containing list of bash-style commands to execute.
# -CPU <int> :number_of_threads
#
# Optional:
# -shuffle :randomly shuffles the command order.
# -failed_cmds <str> :filename to capture failed commands. default("FailedCommands")
# -v :simple progress monitoring.
# -vv :increased verbosity in progress monitoring.
软件二:parallel
官网
Linux下的并行神器——parallel
软件三:pwait
https://github.com/wting/pwait or https://github.com/diazona/pwait
3.bash最简单的并行化--- 后台运行& + wait函数
#串行执行,耗时30秒
for ((i=1;i<=3;i++));do
{
sleep 3
echo "Job $i is DONE"
}
done
#并行执行,耗时3秒
for ((i=1;i<=3;i++));do
{
sleep 3
echo "Job $i is DONE"
} &
done
wait
网友评论