当前位置:网站首页>shell脚本多进程并发写法实例(高阶修炼)
shell脚本多进程并发写法实例(高阶修炼)
2022-06-26 14:53:00 【波哥】
现实工作场景中有很多为了实现快速处理,而采用并发执行.其他语言实现并发非常容易.
那么shell脚本最为linux上面最友好的脚本语言能实现并发嘛?
答案是必须的哈!~
那么波哥这里就写个例子分享给大家哈!~
#!/bin/bash
#并发数
pnum=6
#想要执行的函数
task () {
echo "$u start"
sleep 5
echo "$u done"
}
FifoFile="$$.fifo"
mkfifo $FifoFile
exec 6<>$FifoFile
rm $FifoFile
for ((i=0;i<=$pnum;i++));do echo;done >&6
#执行20次
for u in `seq 1 20`
do
read -u6
{
#调用函数
task
#并发执行函数打印结果日志
[ $? -eq 0 ] && echo "${u} 次成功" || echo "${u} 次失败"
echo >&6
} &
done
wait
exec 6>&-套用上面的例子就可以实现并发处理了哈!~
边栏推荐
猜你喜欢

Where do people get their top energy?

【使用yarn运行报错】The engine “node“ is incompatible with this module.

How to mount cloud disks in ECS

710. 黑名单中的随机数

feil_uVission4左侧工目录消失

Deploy the flask environment using the pagoda panel

一篇抄十篇,CVPR Oral被指大量抄袭,大会最后一天曝光!

设计人员拿到的工程坐标系等高线CAD图如何加载进图新地球

使用 Abp.Zero 搭建第三方登录模块(一):原理篇

The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
随机推荐
Authoritative announcement on the recruitment of teachers in Yan'an University in 2022
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
JVM 输出 GC 日志导致 JVM 卡住,我 TM 人傻了
vue中缓存页面 keepAlive使用
Use abp Zero builds a third-party login module (II): server development
Keil4打开单片机工程一片空白,cpu100%程序卡死的问题解决
TCP 复位攻击原理
Attention meets geometry: geometry guided spatiotemporal attention consistency self supervised monocular depth estimation
R language uses ggplot2 to visualize the results of Poisson regression model and count results under different parameter combinations
cluster addslots建立集群
[solo π] ADB connects multiple mobile phones
[cloud native] codeless IVX editor programmable by "everyone"
聊聊几位大厂清华同学的近况
Excel-vba quick start (II. Condition judgment and circulation)
重磅白皮书发布,华为持续引领未来智慧园区建设新模式
The intersect function in the dplyr package of R language obtains the data lines that exist in both dataframes and the data lines that cross the two dataframes
信息学奥赛一本通 1400:统计单词数 (字符串匹配)
Pod scheduling of kubernetes
子查询的使用
Informatics Olympiad 1405: sum and product of prime numbers (thinking problem)