![iputils ping 程序 -W 选项何时等待两个 RTT?](https://linux22.com/image/110706/iputils%20ping%20%E7%A8%8B%E5%BA%8F%20-W%20%E9%80%89%E9%A1%B9%E4%BD%95%E6%97%B6%E7%AD%89%E5%BE%85%E4%B8%A4%E4%B8%AA%20RTT%EF%BC%9F.png)
iputils ping 程序为该-W
选项指定以下内容:
-W timeout
Time to wait for a response, in seconds. The option affects only
timeout in absence of any responses, otherwise ping waits for
two RTTs.
-W
在什么情况下该值会不是生效,并且“等待两个RTT”适用吗?
答案1
在 ping 序列期间,被 ping 的机器有任何回复的情况。在这种情况下,ping
在等于 ping 序列中所有 RTT 的最大值乘以 2 的时间后超时。
在此示例中,超时设置为 55.392 × 2 = 110.784 毫秒:
PING www.google.com (173.194.44.80) 56(84) bytes of data.
64 bytes from 173.194.44.80: icmp_seq=1 ttl=47 time=55.3 ms
64 bytes from 173.194.44.80: icmp_seq=2 ttl=47 time=52.6 ms
64 bytes from 173.194.44.80: icmp_seq=3 ttl=47 time=52.7 ms
64 bytes from 173.194.44.80: icmp_seq=4 ttl=47 time=53.9 ms
64 bytes from 173.194.44.80: icmp_seq=5 ttl=47 time=52.5 ms
64 bytes from 173.194.44.80: icmp_seq=6 ttl=47 time=52.7 ms
64 bytes from 173.194.44.80: icmp_seq=7 ttl=47 time=52.8 ms
64 bytes from 173.194.44.80: icmp_seq=8 ttl=47 time=53.2 ms
^C
--- www.google.com ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7010ms
rtt min/avg/max/mdev = 52.535/53.273/55.392/0.939 ms
如果您尝试 ping 的计算机根本没有回复:
- 如果不使用该
-W
标志,则 ping 会在一段时间后超时,具体时间取决于实现,通常为 4 或 10 秒 - 如果使用该
-W
标志,则 ping 在指定时间后超时