LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bring back ping process (https://www.linuxquestions.org/questions/linux-general-1/bring-back-ping-process-940820/)

yawningdog 04-20-2012 07:09 AM

Bring back ping process
 
I'm monitoring my connection to a host using a running ping request. Somehow my shell window managed to get closed (I think I may have lost power) and now I cannot get the status of the ping. When I run the top command, ping is still running and remains the top resource hog, so it clearly is still pinging. (Not sure how that woked out, the terminal window closing but the process staying up/restarting.)

Can anyone tell me how to bring the process back up so I can view the status of the ping?

MensaWater 04-20-2012 07:24 AM

When you say "the ping process" what exactly is the name of the process? What is the process ID (PID)? Is it in fact just "ping" or is it a script someone wrote that is doing what you call "the ping process"?

At command line if you type "ps -ef |grep ping" what does it show? If there is a ? in the tty column then it means the process has been backgrounded which is why it is still running. You can background any process by putting ampersand (&) at the end of the line. You can also put nohup at the start of the line to tell it not to hangup when the terminal disconnects.

nohup ping myserver &
Would leave the ping of myserver running forever in the background.

There are methods to background a process and pull it into the foreground but that assumes you're still on the terminal session that backgrounded it which you're not (even if you reconnect from same terminal - it is different session). One can use the "screen" utility to start a session that stays active when disconnecting the physical terminal and later reattach to that running screen session.

If it were me I'd simply find the original ping process, kill it, and start a new one. I can't really see much value in leaving a ping running forever though and some downside (as for example your high cpu usage). I'd suggest instead of running a permanent ping that you do something like a cron job that does a "ping -c 1" every minute. If it works everything is OK otherwise you could script it so it sends you an alert on failure.

yawningdog 04-20-2012 07:58 AM

When I say "the ping process", I'm referring to the fact that the ping program has a viewable PID and therefore counts as a process. If I run ps -ef | grep ping, I get the following

root 28355 28343 0 Mar22 ? pts/4 28-22:30:57 ping 192.168.x.x
root 28357 28322 0 08:41 pts/3 00:00:00 grep --color=auto ping

I'm familiar with the ampersand and nohup tags, and I realize that what I'm asking seems unconventional. I'm also familiar with screen and in retrospect I wish I had used it, but I failed to realize that this would take as long as it has. I know how to stop the process and start a new one and I know that seems like the sensible thing to do. However I have my reasons for not doing this which are, to this subject, strictly academic.

My question stands. How to get the ping results back up to the console? I suppose that if I cannot get it back because the console session is irretrievable, then all is lost and I have to start over. But I want to make sure before I do that.

pan64 04-20-2012 08:32 AM

you need to write the output of ping into a file and use tail to view it.

MensaWater 04-20-2012 09:01 AM

I don't know of any way to get access back to a backgrounded process once you've closed the original session.

What you COULD try to get some data is run "lsof -p 28355" to see what if anything that shows you.

You COULD also use tcpdump to see the actual traffic to/from 192.168.x.x. Or to see all ICMP (ping) traffic:

tcpdump icmp -i any

jschiwal 04-20-2012 09:07 AM

I doubt that the the terminal is truely closed since pts/4 is listed in PS. In any case, the past history of stdout and stderr is already consumed. To view the current output you could try attaching gdb to the process and duplicating stdout.


All times are GMT -5. The time now is 05:57 PM.