【发布时间】:2015-09-16 06:17:18
【问题描述】:
我在 C# (.NET Framework 4.5) 上编写 Windows 服务。 停止服务后,他的进程变成了一个僵尸进程(他不会被“taskkill”杀死)。
大约 3-15 分钟结束:服务工作的时间越长,完成的过程就越长。在调试服务中正确结束并退出所有可见代码。
在工作中,我通过 SSH 执行远程命令。 我注意到执行这样的团队 - 也许是僵尸的原因。 因为下班后无需运行命令,进程立即终止。
为了执行 SSH 命令,我使用 SSH.NET (http://sshnet.codeplex.com/):
public class RenciSSHExecute:ISSHExecutable
{
public string Execute(String host, String user, String password, String command)
{
string result = String.Empty;
Guid guid = Guid.NewGuid();
try
{
using (var client = new Renci.SshNet.SshClient(host, user, password))
{
client.Connect();
Logger.Information("Send SSH command [{0}]: {1}.", guid.ToString(), command);
var cmd = client.RunCommand(command);
result = cmd.Result.Replace("\n", "");
Logger.Information("Result SSH command [{0}]: {1}", guid.ToString(), result);
}
}
catch (Exception e)
{
throw new Exception(String.Format("Failed execution ssh-command: {0} on {1}@{2}. Error message: {2}",
command, user, host, e.Message));
}
return result;
}
}
僵尸的原因是什么,如何解决?
更新:
我使用 “Windows 资源监视器”: 在“关联句柄”部分中,我找到了行:
\Device\Mup\$COMPUTERNAME\PIPE\winreg
这些是 $COMPUTERNAME 已经断开连接的机器,交互完成。
这些线是什么?这可能是僵尸进程的原因吗?
在服务代码中,我使用 Process.GetProcesses 来获取远程 mashine 上正在运行的进程列表:
var remoteProcesses = Process.GetProcesses(remote_client_name);
如果机器关闭,Process.GetProcesses会不会留下一些资源不关闭?
【问题讨论】:
标签: c# service ssh zombie-process