How to set timeout to 'ping' command?

In windows argument -w and number in milliseconds set how long wait echo reply from pinging host.

I'm running now macOS Sierra and -t argument from ping help set count of echo requests. So ping google.com -c 5 and ping google.com -t 5 give the same result - five echo requests with default timeout.

Is there a flag that does what I need?


Solution 1:

Looking at the man page for ping (man ping); under the -i wait option, we see that the default time between sending pings is 1 second:

-i wait

wait seconds between sending each packet. The default is to wait for one second between each packet.

So, using the default of sending 1 packet every 1 second, the options -t and -c will produce the same output.

When we add in a fractional wait time of say, a half second, we should now get 12 packets sent within the 6 seconds:

$ sudo ping -i .5  -t 6 apple.stackexchange.com

PING apple.stackexchange.com (151.101.193.69): 56 data bytes
64 bytes from 151.101.193.69: icmp_seq=0 ttl=58 time=12.509 ms
64 bytes from 151.101.193.69: icmp_seq=1 ttl=58 time=11.990 ms
64 bytes from 151.101.193.69: icmp_seq=2 ttl=58 time=17.027 ms
64 bytes from 151.101.193.69: icmp_seq=3 ttl=58 time=13.173 ms
64 bytes from 151.101.193.69: icmp_seq=4 ttl=58 time=15.752 ms
64 bytes from 151.101.193.69: icmp_seq=5 ttl=58 time=10.337 ms
64 bytes from 151.101.193.69: icmp_seq=6 ttl=58 time=15.484 ms
64 bytes from 151.101.193.69: icmp_seq=7 ttl=58 time=9.653 ms
64 bytes from 151.101.193.69: icmp_seq=8 ttl=58 time=9.734 ms
64 bytes from 151.101.193.69: icmp_seq=9 ttl=58 time=9.486 ms
64 bytes from 151.101.193.69: icmp_seq=10 ttl=58 time=11.321 ms
64 bytes from 151.101.193.69: icmp_seq=11 ttl=58 time=9.549 ms

Twelve responses as expected. Note, that you must run this as root; per the man page for the -i wait option:

The wait time may be fractional, but only the super-user may specify values less than 1 second.

Now, the -W option (capital "W", not lowercase) will be the equivalent to the Windows -w which specifies a wait time between receipt of the packets:

-W waittime Time in milliseconds to wait for a reply for each packet sent. If a reply arrives later, the packet is not printed as replied, but considered as replied when calculating statistics.