What is the difference between ping -w and ping -W?

What is the -w (deadline) flag in ping for? I cannot find a description of it in the ping man page; only for -W, which takes seconds as a parameter. What is the difference between them, and how can I set a ping timeout (if host is not responding) to 200ms?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

From man ping:

-w deadline
Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received. In this case ping does
not stop after count packet are sent, it waits either for deadline
expire or until count probes are answered or for some error
notification from network.

-W timeout
Time to wait for a response, in seconds. The option affects only timeout in absense of any responses, otherwise ping waits for two
RTTs.

That is, -w sets the timeout for the entire program session. If you set -w 30, ping (the program) will exit after 30 seconds.

-W on the other hand sets the timeout for a single ping. If you set -W 1, that particular ping attempt will time out.

As for how to set an individual ping timeout of 200ms, I don’t believe this can be done with iputils‘ version of ping. You might want to try directly programming with an ICMP library.

Method 2

All good answers, but watch out for this quirk if (like me) you’re porting code between platforms. The text below is from the respective ‘man ping’ documentation.

On Mac OS X:

-W waittime

    Time in milliseconds to wait for a reply
    for each packet sent.

On Raspberry Pi:

-W timeout

    Time to wait for a response, in seconds.

I coded on the Mac to wait 1 second (1,000 ms) as -W 1000, but when this code moved to the Pi, it waited for up to 1,000 secs!

Method 3

My manpage (Fedora 18, iputils-20121221-1.fc18) says

   -w deadline
          Specify  a  timeout, in seconds, before ping exits regardless of
          how many packets have been sent or received. In this  case  ping
          does  not  stop after count packet are sent, it waits either for
          deadline expire or until count probes are answered or  for  some
          error notification from network.

   -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.

Method 4

There is also the -em option that shoves each packet in a certain period of time for example:

ping -i 5 <target>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x