How to stop PING command in Linux & Windows? Code Example

Total
0
Shares

Use Ctrl + C or Ctrl + | or Ctrl + Shift + C to stop or terminate PING command in Linux and Windows.

PING is a terminal and command line utility which is used to check connectivity among source and destination. It sends ICMP (Internet Control Message Protocol) messages from one computer to another, recognizing with IP address. It measures the delay between sent message and replied message.

PING is a handy utility which is also used for domain name resolution. Suppose you ping using IP address and it worked successfully. But, on the other hand, it failed when you used the domain host name pointing to the ip. It means there is a problem with DNS lookup.

How to stop Ping command?

Use these keyboard shortcuts to terminate a ping command –

Ctrl + C
Ctrl + |
Ctrl + Shift + C

It works in both Windows and Linux systems. Check this screenshot –

terminating ping using ctrl+c or ctrl+| or ctrl+shift+c

Solution 2: Run Controlled Ping

If you run a ping command like this –

ping akashmittal.com

Then, it will run infinitely and you will have to terminate it using keyboard shortcuts like ctrl+c. But you can also run a defined number of pings. There are flags to set the count. For Windows it is /n count, and for linux we use -c count.

Command for windows

ping /n 10 akashmittal.com

The output will look like this –

C:\Users\akash>ping /n 10 akashmittal.com

Pinging akashmittal.com [104.21.24.98] with 32 bytes of data:
Reply from 104.21.24.98: bytes=32 time=157ms TTL=59
Reply from 104.21.24.98: bytes=32 time=166ms TTL=59
Reply from 104.21.24.98: bytes=32 time=162ms TTL=59
Reply from 104.21.24.98: bytes=32 time=158ms TTL=59
Reply from 104.21.24.98: bytes=32 time=165ms TTL=59
Reply from 104.21.24.98: bytes=32 time=166ms TTL=59
Reply from 104.21.24.98: bytes=32 time=162ms TTL=59
Reply from 104.21.24.98: bytes=32 time=167ms TTL=59
Reply from 104.21.24.98: bytes=32 time=167ms TTL=59
Reply from 104.21.24.98: bytes=32 time=168ms TTL=59

Ping statistics for 104.21.24.98:
    Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 157ms, Maximum = 168ms, Average = 163ms
ping 10 counts on akashmittal.com on windows

Command for Linux

ping -c 10 akashmittal.com

Output –

[email protected]:~$ ping -c 10 akashmittal.com
PING akashmittal.com (104.21.24.98) 56(84) bytes of data.
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=1 ttl=58 time=180 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=2 ttl=58 time=164 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=3 ttl=58 time=164 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=4 ttl=58 time=167 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=5 ttl=58 time=159 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=6 ttl=58 time=172 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=7 ttl=58 time=167 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=8 ttl=58 time=160 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=9 ttl=58 time=159 ms
64 bytes from 104.21.24.98 (104.21.24.98): icmp_seq=10 ttl=58 time=159 ms

--- akashmittal.com ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9267ms
rtt min/avg/max/mdev = 158.508/165.027/180.009/6.565 ms
ping count 10 for akashmittal.com on linux

Conclusion

Use ctrl+c, ctrl+| or ctrl+shift+c to stop ping requests. In this article we saw how to we can use -c and /n flags to define fixed number of pings. So that it will terminate automatically after the count is reached.