Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm starting a ssh tunnel like this:

ssh -f -N $PORT:127.0.0.1:$port example.com

the -f puts ssh into the background, which is what I want. This works, since there is a SSH tunnel set up. But if I use jobs I can't see the ssh connection listed. How come?

share|improve this question
    
Please include your platform –  Andrioid Jul 6 '09 at 13:51
add comment

3 Answers

up vote 4 down vote accepted

Because you didn't use bash to send it into the background. jobs only reports on processes that bash itself has sent to the background; it was ssh itself that "daemonized" it, as ericslaw said. To get jobs to report it, you'd do:

ssh -N $PORT:127.0.0.1:$port example.com &
share|improve this answer
add comment

The ssh process likely daemonized, disconnecting from the shell. You can think of it like this (but possibly not in this order):

The 'ssh' process you launched actually closed all it's file descriptors (stdin,stdout,stderr), disconnected from the tty, and forked another child ssh. then called exit on itself. This orphaned the child process and the original ssh process actually 'completes'.

As a result, the original ssh process is complete and the orphaned process is no longer a 'child' of your shell.

Use 'ps -ef' or 'ps -fu$USER' instead to see the ssh process you are interested in.

share|improve this answer
add comment

You can see what program is listening on the port using command:

lsof -i :port

It will give you ssh pid.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.