7

When I use the 'Ping' command in a terminal window, how do I terminate the ping? I have pinged my router (192.168.1.1) and the results have displayed in the terminal window, but the program keeps running with no indication as to how to terminate.

I can end the command by closing the command terminal window, but I would rather keep it open so I can compare pings with different addresses.

Ubuntu 14.04 LTS

10

There are three options:

  • Manually interrupt the ping command using Ctrl+C, as described in @steeldriver's answer.

  • Use ping's "count" option (-c COUNT) to send exactly COUNT pings and then terminate automatically, as described in @bodhi.zazen's answer.

  • Use ping's "deadline" option (-w DEADLINE) to run for exactly DEADLINE seconds and then terminate automatically.


Of course you can combine the three options. If you pass both a "count" and a "deadline" option, ping will terminate as soon as the first event occurs. And Ctrl+C works always anyway.

Here's an example with a "count" of maximal 10 pings and a "deadline" of 5 seconds, but which got terminated manually using Ctrl+C after 3 pings (^C):

$ ping -c 10 -w 5 askubuntu.com
PING askubuntu.com (104.16.110.188) 56(84) bytes of data.
64 bytes from 104.16.110.188: icmp_seq=1 ttl=56 time=54.6 ms
64 bytes from 104.16.110.188: icmp_seq=2 ttl=56 time=52.5 ms
64 bytes from 104.16.110.188: icmp_seq=3 ttl=56 time=54.0 ms
^C
--- askubuntu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 52.582/53.733/54.611/0.850 ms
  • 2
    Sometimes either the terminal eats CTRL C, or DNS query blocks, in that case you can use CTRL Z followed by kill %1 to suspend the process and then kill it. – Radovan Garabík Jan 26 '16 at 15:11
1

You can use Ctrl+C to send a SIGINT (interrupt signal) to the ping process - see Unix signals

1

Either give ping a count with the -c option :

ping -c 4 google.com

Or use the keys Ctrl+C to terminate the command.

0

You should try Ctrl + C to stop the processus.

  • @CharlesGreen , Actually this answer posted 6 minutes before the accepted one. – user.dz Jan 27 '16 at 15:33
0

You can try ctrl + c to send an interrupt signal, it will terminate the program without closing terminal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.