简体   繁体   English

使用批处理重新启动C ++控制台应用程序不会关闭网络连接

[英]Restart c++ console application using batch doesn't close network connections

I need to restart my application via code and I choose to use a batch file. 我需要通过代码重新启动应用程序,然后选择使用批处理文件。 When the application starts it creates a batch like this: 当应用程序启动时,它将创建一个如下的批处理:

taskkill /f /im AudioService.exe
TIMEOUT 10
start "AudioService" "AudioService.exe"

then I call it from the code (using Poco Library ): 然后我从代码中调用它(使用Poco Library ):

Poco::Process::Args args;
Poco::Process::launch(RESTART_SCRIPT_NAME, args);

Now, it works except for the fact that the network connections are not closed and, when the application restart, the Bind() function fails. 现在,除了网络连接未关闭以及应用程序重新启动时,Bind()函数失败外,它均有效。

Instead, if I run the batch file "by hand" from the Explorer all works as expected: the application and its network connection are killed. 相反,如果我从资源管理器中“手动”运行批处理文件,则所有工作均按预期进行:该应用程序及其网络连接被杀死。

Someone could give me some hint on why this happen? 有人可以给我提示为什么会发生这种情况吗?

If an application closes without closing its handles, the OS is responsible for dealing with it. 如果一个应用程序关闭而没有关闭其句柄,则操作系统负责处理它。 When the OS decides to close handles is up to the OS, not your application, so you may have to wait a little while for it to clean them up. 当操作系统决定关闭句柄时,应由操作系统决定,而不是由应用程序决定,因此您可能需要等待一段时间才能清理它们。

You may wish to look up what signal handlers are so that your application can ensure it always cleans up nicely 您可能希望查看什么是信号处理程序,以便您的应用程序可以确保始终很好地进行清理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM