【发布时间】:2011-06-09 17:35:46
【问题描述】:
我有一个 C++ 应用程序,它使用 ssh 来建立与服务器的连接。我发现有时 ssh 会话在调用服务器的命令退出后很长时间仍然存在。查看 ssh 的 Centos4 手册页,我看到以下内容:
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.
我看到命令已经退出,所以我想不是所有的 X11 和 TCP/IP 连接都已关闭。我如何才能确定哪些 ssh 正在等待,以便我可以修复我的召唤命令的 C++ 应用程序,以清理留下的任何东西,使 ssh 保持打开状态。
我想知道为什么这种失败只在某些时候发生,而不是在每次调用时发生?它似乎发生在大约 50% 的时间里。我的 C++ 应用程序会留下什么来触发这个?
更多背景:服务器是一个守护进程,当启动时,它分叉并且父进程退出,让子进程继续运行。客户端召唤方式:
popen("ssh -n -o ConnectTimeout=300 user@host \"sererApp argsHere\""
" 2>&1 < /dev/null", "r")
【问题讨论】: