如何找出为什么ssh会话不退出有时? [英] How to figure out why ssh session does not exit sometimes?
问题描述
我有一个C ++应用程序使用ssh来召集到服务器的连接。我发现有时ssh会话在命令召唤服务器已经退出之后很久。看看Centos4的ssh页面,我看到以下内容:
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:
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打开。
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.
我不知道为什么这种失败只发生一些时间,而不是每次调用?它似乎发生大约50%的时间。我的C ++应用程序可以触发这个?
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?
更多背景:服务器是一个守护进程,启动时,它分叉和父退出,让子运行。客户端使用以下命令召集:
More background: The server is a daemon, when launched, it forks and the parent exits, leaving the child running. The client summons by using:
popen("ssh -n -o ConnectTimeout=300 user@host \"sererApp argsHere\""
" 2>&1 < /dev/null", "r")
推荐答案
使用 libssh
或 libssh2
c $ c> popen(3)从C只调用 ssh(1)
,它本身是另一个C程序。如果你想要我的个人经验,我会说 libssh2
- 我用它在一个C ++程序,它的工作原理。
Use libssh
or libssh2
, rather than calling popen(3)
from C only to invoke ssh(1)
which itself is another C program. If you want my personal experience, I'd say try libssh2
- I've used it in a C++ program and it works.
这篇关于如何找出为什么ssh会话不退出有时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!