Board logo

标题: CentOS8使用多线程+Ping [打印本页]

作者: admin    时间: 2021-12-15 11:48     标题: CentOS8使用多线程+Ping

操作系统的版本信息: [root@centos8 ~]# cat /etc/redhat-release CentOS Linux release 8.2.2004 (Core) [root@centos8 ~]# [root@centos8 ~]# uname -r 4.18.0-193.el8.x86_64 Python的版本信息: [root@centos8 ~]# python3 --version Python 3.6.8 ############ 例子一: [root@centos8 ~]# cat xx.py
  1. #coding=utf-8
  2. import _thread
  3. from time import sleep
  4. import datetime,os
  5. def func1(lock):
  6. dt = datetime.datetime.now()
  7. tt = dt.strftime('%Y%m%d_%H%M%S')
  8. Key_t ="\n\n检测时间:" + tt + "\n"
  9. Path_1 = "/root/1.txt"
  10. f_name = open(Path_1,'a') #写入(追加)具体检测时间到文件
  11. f_name.write(Key_t)
  12. f_name.close()
  13. #调用Linux命令
  14. os.system("ping blog.zhuohua.store -c 10 >> /root/1.txt")
  15. sleep(120) #线程一休眠120秒;各个线程的休眠时间要保持一致
  16. lock.release()
  17. def func2(lock):
  18. dt = datetime.datetime.now()
  19. tt = dt.strftime('%Y%m%d_%H%M%S')
  20. Key_t ="\n\n检测时间:" + tt + "\n"
  21. Path_1 = "/root/2.log"
  22. f_name = open(Path_1,'a')
  23. f_name.write(Key_t)
  24. f_name.close()
  25. os.system("ping www.baidu.com -c 10 >> /root/2.log")
  26. sleep(120) #线程二休眠120秒;各个线程的休眠时间要保持一致
  27. lock.release()
  28. def func_main():
  29. fields_1 = range(0, 2) # "2" 意味着有2个线程,依此类推
  30. fields_2 = []
  31. for Key_1 in fields_1:
  32. Key_1 = _thread.allocate_lock()
  33. Key_1.acquire()
  34. fields_2.append(Key_1)
  35. # [0]、[1]代表线程号,依此类推;分别给每个函数的一个变量进行赋值
  36. _thread.start_new_thread(func1,(fields_2[0],))
  37. _thread.start_new_thread(func2,(fields_2[1],))
  38. for i in fields_1:
  39. while fields_2[i].locked():
  40. pass
  41. if __name__ == '__main__':
  42. index_1 = 0
  43. while index_1 < 3: #进程执行3次后自动结束
  44. func_main()
  45. index_1 = index_1 + 1
复制代码
脚本运行中的效果:(组合键Ctrl+c可以结束脚本的运行) 图片1.png ###### 文件/root/1.txt自动记录的数据:(有三次的Ping结果) [root@centos8 ~]# cat 1.txt 检测时间:20210302_193113 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=18.4 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=25.2 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=17.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=17.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=7 ttl=128 time=22.4 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=21.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=16.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=10 ttl=128 time=18.9 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 8 received, 20% packet loss, time 125ms rtt min/avg/max/mdev = 16.808/19.926/25.199/2.714 ms 检测时间:20210302_193323 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=19.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=19.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=20.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=17.4 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=5 ttl=128 time=124 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=6 ttl=128 time=24.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=28.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=18.6 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=10 ttl=128 time=17.9 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 9 received, 10% packet loss, time 113ms rtt min/avg/max/mdev = 17.361/32.308/123.532/32.429 ms 检测时间:20210302_193534 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=17.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=16.9 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=19.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=16.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=5 ttl=128 time=18.9 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=6 ttl=128 time=17.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=7 ttl=128 time=17.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=19.0 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=17.4 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=10 ttl=128 time=123 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 48ms rtt min/avg/max/mdev = 16.914/28.448/122.792/31.460 ms [root@centos8 ~]# ###### 文件/root/2.log自动记录的数据:(所有线程的开始时间都是一样的) [root@centos8 ~]# cat 2.log 检测时间:20210302_193113 PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=10.8 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=25.3 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=10.9 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=10.8 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=7 ttl=128 time=8.67 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=8 ttl=128 time=9.43 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=9 ttl=128 time=9.25 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=10 ttl=128 time=11.8 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 8 received, 20% packet loss, time 126ms rtt min/avg/max/mdev = 8.672/12.108/25.303/5.079 ms 检测时间:20210302_193323 PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=10.6 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=16.4 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=18.2 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=12.3 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=26.7 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=128 time=19.9 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=9 ttl=128 time=9.38 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=10 ttl=128 time=11.3 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 8 received, 20% packet loss, time 134ms rtt min/avg/max/mdev = 9.377/15.583/26.681/5.503 ms 检测时间:20210302_193534 PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=10.3 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=8.89 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=11.5 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=9.03 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=9.07 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=128 time=13.5 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=7 ttl=128 time=9.02 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=8 ttl=128 time=12.6 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=9 ttl=128 time=9.73 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=10 ttl=128 time=29.2 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 47ms rtt min/avg/max/mdev = 8.890/12.278/29.204/5.849 ms [root@centos8 ~]# ############ 例子二: [root@centos8 ~]# cat xx.py
  1. #coding=utf-8
  2. import _thread
  3. from time import sleep
  4. import datetime,os
  5. def func1(n_sec,lock):
  6. dt = datetime.datetime.now()
  7. tt = dt.strftime('%Y%m%d_%H%M%S')
  8. Key_t ="\n\n检测时间:" + tt + "\n"
  9. Path_1 = "/root/1.txt"
  10. f_name = open(Path_1,'a') #写入(追加)具体检测时间到文件
  11. f_name.write(Key_t)
  12. f_name.close()
  13. #调用Linux命令
  14. os.system("ping blog.zhuohua.store -c 10 >> /root/1.txt")
  15. sleep(n_sec)
  16. lock.release()
  17. def func2(n_sec,lock):
  18. dt = datetime.datetime.now()
  19. tt = dt.strftime('%Y%m%d_%H%M%S')
  20. Key_t ="\n\n检测时间:" + tt + "\n"
  21. Path_1 = "/root/2.log"
  22. f_name = open(Path_1,'a')
  23. f_name.write(Key_t)
  24. f_name.close()
  25. os.system("ping www.baidu.com -c 10 >> /root/2.log")
  26. sleep(n_sec)
  27. lock.release()
  28. def func3(n_sec,lock):
  29. dt = datetime.datetime.now()
  30. tt = dt.strftime('%Y%m%d_%H%M%S')
  31. Key_t ="\n\n检测时间:" + tt + "\n"
  32. Path_1 = "/root/3.log"
  33. f_name = open(Path_1,'a')
  34. f_name.write(Key_t)
  35. f_name.close()
  36. os.system("ping www.sina.com -c 10 >> /root/3.log")
  37. sleep(n_sec)
  38. lock.release()
  39. def func_main():
  40. fields_1 = range(0, 3) # "3" 意味着有3个线程,依此类推
  41. fields_2 = []
  42. for Key_1 in fields_1:
  43. Key_1 = _thread.allocate_lock()
  44. Key_1.acquire()
  45. fields_2.append(Key_1)
  46. # [0]、[1]、[2]代表线程号,依此类推;分别给每个函数的两个变量进行赋值
  47. # 各个线程的休眠时间要保持一致
  48. _thread.start_new_thread(func1,(60,fields_2[0])) #线程一休眠60秒
  49. _thread.start_new_thread(func2,(60,fields_2[1])) #线程二休眠60秒
  50. _thread.start_new_thread(func3,(60,fields_2[2])) #线程三休眠60秒
  51. for i in fields_1:
  52. while fields_2[i].locked():
  53. pass
  54. if __name__ == '__main__':
  55. while True: #进程会无限次地自动执行下去
  56. func_main()
复制代码
脚本运行中的效果:(组合键Ctrl+c可以结束脚本的运行) 图片1.png ###### 文件/root/1.txt自动记录的数据:(以下只是其中连续四次的结果) [root@centos8 ~]# cat 1.txt 检测时间:20210302_194318 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=18.9 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=17.2 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=16.9 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=18.6 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=5 ttl=128 time=17.5 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=6 ttl=128 time=19.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=7 ttl=128 time=20.0 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=20.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=20.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=10 ttl=128 time=16.7 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 48ms rtt min/avg/max/mdev = 16.689/18.657/20.339/1.390 ms 检测时间:20210302_194428 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=21.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=22.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=17.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=96.4 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=5 ttl=128 time=16.5 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=6 ttl=128 time=20.6 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=7 ttl=128 time=19.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=19.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=20.8 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 9 received, 10% packet loss, time 60ms rtt min/avg/max/mdev = 16.469/28.424/96.405/24.098 ms 检测时间:20210302_194538 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=18.4 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=29.1 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=19.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=18.1 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=5 ttl=128 time=16.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=6 ttl=128 time=18.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=7 ttl=128 time=22.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=17.2 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=19.6 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=10 ttl=128 time=19.2 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 49ms rtt min/avg/max/mdev = 16.953/19.952/29.066/3.370 ms 检测时间:20210302_194647 PING blog.zhuohua.store (47.75.39.177) 56(84) bytes of data. 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=1 ttl=128 time=16.10 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=2 ttl=128 time=16.8 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=3 ttl=128 time=17.6 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=4 ttl=128 time=19.3 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=5 ttl=128 time=17.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=6 ttl=128 time=18.7 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=7 ttl=128 time=18.6 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=8 ttl=128 time=17.9 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=9 ttl=128 time=17.9 ms 64 bytes from 47.75.39.177 (47.75.39.177): icmp_seq=10 ttl=128 time=18.9 ms --- blog.zhuohua.store ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 35ms rtt min/avg/max/mdev = 16.849/18.044/19.285/0.781 ms [root@centos8 ~]# ###### 文件/root/2.log自动记录的数据:(以下只是其中连续四次的结果) [root@centos8 ~]# cat 2.log 检测时间:20210302_194318 PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=11.1 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=15.3 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=11.10 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=12.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=128 time=13.1 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=128 time=10.9 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=7 ttl=128 time=11.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=8 ttl=128 time=11.8 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=9 ttl=128 time=10.7 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=10 ttl=128 time=10.5 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 47ms rtt min/avg/max/mdev = 10.487/11.950/15.259/1.371 ms 检测时间:20210302_194428 PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=17.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=11.5 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=10.3 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=90.3 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=128 time=10.8 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=128 time=13.4 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=7 ttl=128 time=13.0 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=8 ttl=128 time=12.8 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=9 ttl=128 time=20.5 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 9 received, 10% packet loss, time 61ms rtt min/avg/max/mdev = 10.338/22.240/90.334/24.275 ms 检测时间:20210302_194538 PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=14.7 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=25.7 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=15.4 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=10.1 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=128 time=10.0 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=128 time=18.5 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=7 ttl=128 time=15.8 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=8 ttl=128 time=11.3 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=9 ttl=128 time=12.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=10 ttl=128 time=13.3 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 49ms rtt min/avg/max/mdev = 10.011/14.749/25.742/4.452 ms 检测时间:20210302_194647 PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=9.100 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=11.2 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=13.5 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=9.57 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=9.03 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=128 time=10.2 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=7 ttl=128 time=11.7 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=8 ttl=128 time=10.7 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=9 ttl=128 time=8.83 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=10 ttl=128 time=8.71 ms --- www.a.shifen.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 45ms rtt min/avg/max/mdev = 8.714/10.355/13.495/1.427 ms [root@centos8 ~]# ###### 文件/root/3.log自动记录的数据:(以下只是其中连续四次的结果) [root@centos8 ~]# cat 3.log 检测时间:20210302_194318 PING spool.grid.sinaedge.com (183.60.95.201) 56(84) bytes of data. 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=1 ttl=128 time=12.4 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=2 ttl=128 time=9.65 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=3 ttl=128 time=12.2 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=4 ttl=128 time=9.83 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=5 ttl=128 time=11.6 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=6 ttl=128 time=10.9 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=7 ttl=128 time=9.68 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=8 ttl=128 time=8.64 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=9 ttl=128 time=8.69 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=10 ttl=128 time=9.91 ms --- spool.grid.sinaedge.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 49ms rtt min/avg/max/mdev = 8.638/10.351/12.411/1.293 ms 检测时间:20210302_194428 PING spool.grid.sinaedge.com (183.60.95.201) 56(84) bytes of data. 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=1 ttl=128 time=14.7 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=2 ttl=128 time=10.7 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=3 ttl=128 time=9.11 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=4 ttl=128 time=90.4 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=5 ttl=128 time=10.9 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=6 ttl=128 time=13.4 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=7 ttl=128 time=8.21 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=8 ttl=128 time=12.5 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=9 ttl=128 time=20.5 ms --- spool.grid.sinaedge.com ping statistics --- 10 packets transmitted, 9 received, 10% packet loss, time 60ms rtt min/avg/max/mdev = 8.212/21.157/90.377/24.710 ms 检测时间:20210302_194538 PING spool.grid.sinaedge.com (183.60.95.201) 56(84) bytes of data. 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=1 ttl=128 time=10.10 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=2 ttl=128 time=19.5 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=3 ttl=128 time=9.08 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=4 ttl=128 time=10.2 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=5 ttl=128 time=8.31 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=6 ttl=128 time=9.53 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=7 ttl=128 time=10.8 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=8 ttl=128 time=8.14 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=9 ttl=128 time=12.6 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=10 ttl=128 time=13.2 ms --- spool.grid.sinaedge.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 49ms rtt min/avg/max/mdev = 8.144/11.231/19.459/3.171 ms 检测时间:20210302_194647 PING spool.grid.sinaedge.com (183.60.95.201) 56(84) bytes of data. 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=1 ttl=128 time=10.3 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=2 ttl=128 time=13.3 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=3 ttl=128 time=8.32 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=4 ttl=128 time=14.1 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=5 ttl=128 time=9.68 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=6 ttl=128 time=12.2 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=7 ttl=128 time=9.68 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=8 ttl=128 time=8.31 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=9 ttl=128 time=10.3 ms 64 bytes from 183.60.95.201 (183.60.95.201): icmp_seq=10 ttl=128 time=9.18 ms --- spool.grid.sinaedge.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 34ms rtt min/avg/max/mdev = 8.313/10.542/14.050/1.906 ms [root@centos8 ~]# 相关文章: Timer/sleep CentOS6使用Ping Python3使用多线程/线程锁 CentOS8使用多进程+Ping

图片附件: 图片1.png (2022-3-2 20:16, 10.15 KB) / 下载次数 68
http://blog.zhuohua.store/attachment.php?aid=19140&k=372ee7b55d3c399a991043bd573293b0&t=1714806782&sid=2TtshT



图片附件: 图片1.png (2022-3-2 20:17, 10.15 KB) / 下载次数 66
http://blog.zhuohua.store/attachment.php?aid=19141&k=286cc45398890801c2ded1187daef46c&t=1714806782&sid=2TtshT






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2