最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
linux中Shell并发编程示例
时间:2014-10-06 编辑:简简单单 来源:一聚教程网
在Python中,有很多模块都可以实现并发编程,比如 threading, processing, eventlet 与 Stackless Python 等。
那么对于Shell而言,又如何实现呢?其实原理很简单,我采用的方法是:
1. 将需要执行的任务分批放入后台执行;
2. 将后台执行的命令结果汇总到指定的文件中;
3. 使用wait命令来等待所有任务执行结束。
下面的脚本就用到了这样的并发编程方法,实现的功能是:
快速(3-4秒内)对相同C网内的所有IP(255个)通过命令ping进行测试并返回结果。
代码如下 | 复制代码 |
vim fastping.sh #!/bin/bash # default settings # function print_help # check the parameter # check the network parameter's format # clean the output file function pingable(){ function unpingable(){ # get the check type # ping as paraller mode and write output into file # wait for all ping processes done # print output with better order Examples: There are "142" "pingable" IPs begin with "192.168.1" : real 0m3.201s |
相关文章
- Linux的文件权限解析 10-20
- Git文件删除操作命令解析 10-20
- Linux apache实现https的配置教程 10-18
- 远程登录Linux CentOS系统教程 10-11
- UOS系统连接打印机教程 10-10
- Linux系统安装brother打印机驱动并且设置网络打印机教程 10-10