2011-03-22 43 views
2

我有一个程序,在子进程中ssh进入一个服务器并执行一个命令并返回。父母通过信号处理孩子(SIGCHLD,SIG_IGN)。有没有一种方式,如果ssh服务器没有响应,并且从命令行输入SSH并永远等待另一台服务器,孩子会超时?fork execlp调用中的子进程超时

回答

0

ssh_config(5)

ConnectTimeout 
     Specifies the timeout (in seconds) used when 
     connecting to the SSH server, instead of using the 
     default system TCP timeout. This value is used only 
     when the target is down or really unreachable, not 
     when it refuses the connection. 

你可以看到它工作得很好,以缩短延迟:

$ time ssh -oConnectTimeout=1 ehrlichman 
ssh: connect to host ehrlichman port 22: Connection timed out 

real 0m1.038s 
user 0m0.000s 
sys 0m0.000s 
$ 

但它可能不会增加对永远延迟工作;允许TCP握手花费的时间比内核被配置为等待时间似乎不太可能。