当前位置:网站首页>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>&-套用上面的例子就可以实现并发处理了哈!~
边栏推荐
- 券商经理给的开户链接办理股票开户安全吗?我想开个户
- TS常用数据类型总结
- IP certificate application process of sectigo
- [solo π] ADB connects multiple mobile phones
- Common operation and Principle Exploration of stream
- 710. random numbers in the blacklist
- 券商经理给的开户链接安全吗?找谁可以开户啊?
- 网上找客户经理办理股票开户安全吗??
- MHA high availability coordination and failover
- Unity C# 网络学习(十)——UnityWebRequest(一)
猜你喜欢

ETL过程中数据精度不准确问题

Authoritative announcement on the recruitment of teachers in Yan'an University in 2022

15 bs对象.节点名称.节点名称.string 获取嵌套节点内容

【soloπ】adb连接单个多个手机

TS常用数据类型总结

This is the graceful file system mounting method, which is effective through personal testing

Complimentary Book Cognitive Control: how does our brain accomplish tasks?

Mark一下 Unity3d在Inspector中选中不了资源即Project锁定问题

BLE抓包调试信息分析

Redis-集群
随机推荐
Minister of investment of Indonesia: Hon Hai is considering establishing electric bus system and urban Internet of things in its new capital
聊聊几位大厂清华同学的近况
手机股票注册开户安全吗,有没有什么风险?
Practical website recommendations worth collecting for College Students
Is it safe to open a stock account through the account opening link given by the broker manager? I want to open an account
Is it safe to open a stock account with the account manager online??
The DOTPLOT function in the epidisplay package of R language visualizes the frequency of data points in different intervals in the form of point graphs, specifies the grouping parameters with the by p
Halcon C # sets the form font and adaptively displays pictures
编译配置in文件
Excerpt from three body
Mathematical modeling of war preparation 30 regression analysis 2
Use abp Zero builds a third-party login module (II): server development
券商经理给的开户二维码安全吗?找谁可以开户啊?
使用 Abp.Zero 搭建第三方登录模块(二):服务端开发
Datasets dataset class (2)
Attention meets Geometry:几何引导的时空注意一致性自监督单目深度估计
Redis-集群
Document 1
Redis集群消息
子查询的使用