• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Solved Ping command did not stop

Rohit

New Member


Messages: 3

#1
Hi All,

Thanks in advance.

I ran the following command:
ping 8.8.8.8 &

The command was running continuously and even ctrl+c multiple times could'nt stop it finally had to reboot.

Can someone please explain why this happened ?

Thanks
 
Last edited by a moderator:

k.jacker

Well-Known Member

Thanks: 207
Messages: 403

#3
You were running ping as a background job because you used & at the end.
That means the job is detached from direct input via the shell put still sends it output to stdout.
You can not stop it via ctrl+c

To understand what's going on you might want to run it like this: ping -i 10 8.8.8.8 &
You have now specified an interval of 10 senconds before the next ping is send so it won't flood your terminal with it's output completely.

While ping is running in the background now, with a ping send only every ten seconds type this: jobs
It will show that there is a ping running as a background job. To make the backround job run in the foreground again, type: fg

Now hit ctrl+c and see how you can interact with it again.

Run ping -i 10 8.8.8.8 & again and type fg agin, but don't hit ctrl+c now but instead hit ctrl+z

You now have send a STOP signal to the ping process, it is suspended in it's current state now.
While suspended or running in background you can allways check if the is a job running in the background when you type jobs.

Now you could make it running in the backgound again by typing bg or make it running in foregound by typing fg.

In the output from jobs the [1] indicates ping is job number 1 and it will show it's current state also.
If you want to stop the ping while it's detached from direct interaction (suspended or running in the background) you simply type kill %1 and it's gone,
check with jobs again.

This applies to the standard csh shell an for other c-shell compatible shells.
Check the tcsh(1) manpage, section "Jobs"

You can use ctrl+z whenever you want. The tcsh manpage is huge and contains of 3000++ lines.
So after you found the "Jobs" section, you could hit ctrl+z, then check for background jobs with jobs and pick up exactly where you left by
typing fg again.

Happy playing ;)
 

k.jacker

Well-Known Member

Thanks: 207
Messages: 403

#5
You're welcome. It's allways nice to help and get help.
You might want to mark the thread as solved, if it is :)
 
Top