title: How to figure out why ssh session does not exit sometimes?
body: <p>I have a C++ application that uses ssh to summon a connection to the server.  I find that sometimes the ssh session is left lying around long after the command to summon the server has exited.  Looking at the Centos4 man page for ssh I see the following:</p>
  
  <pre><code> The session terminates when the command or shell on the remote machine
   exits and all X11 and TCP/IP connections have been closed.  The exit
   status of the remote program is returned as the exit status of ssh.
  </code></pre>
  
  <p>I see that the command has exited, so I imagine not all the X11 and TCP/IP connections have been closed.  How can I figure out which of these ssh is waiting for so that I can fix my summon command's C++ application to clean up whatever is being left behind that keeps the ssh open.</p>
  
  <p>I wonder why this failure only occurs some of the time and not on every invocation?  It seems to occur approximately 50% of the time.  What could my C++ application be leaving around to trigger this?</p>
  
  <p>More background: The server is a daemon, when launched, it forks and the parent exits, leaving the child running.  The client summons by using:</p>
  
  <pre><code>popen("ssh -n -o ConnectTimeout=300 user@host \"sererApp argsHere\""
        " 2&gt;&amp;1 &lt; /dev/null", "r")
  </code></pre>