我使用Mina SSHD客户端在OpenSSH服务器上运行远程命令。 我正在远程服务器上执行一个长时间运行的命令,并希望它在客户端会话关闭时终止。断开连接时终止远程ssh命令
,当我从我的PC终端运行此命令:
\#ssh -t [email protected] sleep 12345
这是我发现在远程机器上:
\# ps -axf
---- Omitted for clarity
12158 ? Ss 0:29 /usr/sbin/sshd -4
22708 ? Ss 0:11 \\_ sshd: [email protected]/3,pts/4
16894 pts/3 Ss 0:00 | \\_ -bash
17750 pts/3 R+ 0:00 | | \\_ ps -axf
17606 pts/4 Ss+ 0:00 | \\_ sleep 12345
---- Omitted for clarity
当我杀了SSH客户端我的机器“睡12345 '在远程机器上终止。
但是,当我运行完全相同的使用Mina Java SSH客户端,这就是我所看到的。
SshClient client = SshClient.setUpDefaultClient();
client.start();
ConnectFuture connect = client.connect("user", "server", 22);
connect.await(10000); //ms
ClientSession session = connect.getSession();
session.addPasswordIdentity("password");
AuthFuture auth = session.auth();
auth.await(10000);
ClientChannel channel = session.createExecChannel("sleep 12345");
OpenFuture open = channel.open();
open.await(10000);
Thread.sleep(15000); // ms, wait for command to run
channel.close(true);
session.close(true);
client.stop();
\# ps -axf
---- Omitted for clarity
27364 ? Ss 0:00 \\_ sshd: [email protected]/0
3277 pts/0 Ss 0:00 | \\_ -bash
22306 pts/0 R+ 0:00 | \\_ ps axf
21699 ? Ss 0:00 \\_ sshd: [email protected]
21796 ? Ss 0:00 \\_ sleep 12345
---- Omitted for clarity
代码后终止命令的上级变成初始化PID:
\# ps -axf
21796 ? Ss 0:00 sleep 12345
\#ps -ef | grep sleep
root 21796 1 0 08:26 ? 00:00:00 sleep 12345
有一些˚F滞后还是选项在Mina中导致它在关闭会话时终止我在远程服务器上的命令?