我有一个运行ssh命令的工具,这样我就可以通过反向ssh连接到linux pc。当我想要更新用.Net Core 2.1编写的工具时,更新程序会停止工具的进程并更新文件。但是通过停止该工具,之前使用Process.Start()启动的ssh进程也将关闭,因为ssh进程是该工具的一个子进程。
有没有办法从我的工具中“断绝”子ssh进程,这样我就不会在更新程序运行时断开连接?
运行Ubuntu...
C#:
case UssGatewayFunction.NPIConnectSSH:
Log.Information("Connect to MyCompany via ssh");
try
{
Process.Start("ssh", "-R 3521:localhost:22 -p 9450 myuser@1.2.3.4 sleep 30");
response = new DefaultRes(true, UssGatewayFunction.NPIConnectSSH);
}
catch (Exception ex)
{
Log.Error($"Can't start ssh: {ex.Message}");
response = new DefaultRes(false, UssGatewayFunction.NPIConnectSSH);
}Updater.sh:
systemctl stop gateway.service
if pgrep "gateway" >/dev/null 2>&1 ; then
#here i loose the ssh connection
pkill -x "init-gateway" || true
pkill -x "gateway" || true
fi
#now just the extracting happenshttps://stackoverflow.com/questions/54292654
复制相似问题