Re: How to kill a background ssh process?

"CP" == clodoaldo pinto <clodoaldo.pinto@xxxxxxxxx> writes:

CP> I need to have a background ssh tunnel. It is setup like this: $
CP> ssh -n -N -C -o "StrictHostKeyChecking no" -L 5433:localhost:5432
CP> &

CP> It needs to eventually be killed and restarted with another server
CP> IP. What I'm doing is sending it a SIGTERM and it works but
CP> leaves a defunct process. This is not too big a deal but I want it
CP> clean.

CP> I have read from the man that a ~ followed by a . from stdin
CP> closes the connection, but the manual also states that the -n
CP> option must be used when ssh is to run in the background.

CP> What is the best approach?

Try using -f instead of having the shell put it under job control with "&".

CP> Regards, Clodoaldo PInto

Richard Silverman