How to terminate ping <dest> &

Solution 1:

First enter fg into same terminal that your ping command is running (it brings the process into the foreground), then press Ctrl+c to stop the process.

enter image description here

Solution 2:

If it is your one and only background job you can kill it with kill %1. If not sure you can list all your background jobs with jobs and use kill %<n> where you replace n by the number of your ping job.

Solution 3:

When you send a process to the background, whether by using ctrl-z or by & at the end of the command, you get an output in the following format: [index] process-id. If you send multiple processes to the background, the index will keep incrementing every time.

For example:

$ sleep 100 &
[1] 41608
$ sleep 101 &
[2] 41609
$ sleep 102 &
[3] 41610
$ sleep 103 &
[4] 41611
$ sleep 104 &
[5] 41612
$ sleep 105 &
[6] 41613
$ sleep 106 &
[7] 41614

In order to stop a specific one, you can either use kill <process-id> or use fg <index> followed by ctrl-c

Example using the previous output:

$ kill 41614

or

$ fg 7
sleep 106
^C

Solution 4:

Launch a new tab of terminal, run:

$ pgrep ping
  2564

Then kill the pid using kill command:

$ kill 2564