C# 中通过 Process.Kill() 终止的进程的退出代码

发布于 2024-08-25 17:08:26 字数 144 浏览 5 评论 0原文

如果在我的 C# 应用程序中,我正在创建一个可以正常终止或开始行为异常的子进程,在这种情况下,我通过调用 Process.Kill() 来终止它。但是,我想知道该进程是否已退出通常情况下。我知道我可以获得终止进程的错误代码,但是正常的退出代码是什么以及什么表示该进程被终止?

If in my C# application, I am creating a child process that can either terminate normally, or start misbehaving, in which case I terminate it with a call to Process.Kill().However, I would like to know if the process has exited normally.I know I can get the error code of a terminated process, but what would be a normal exit code and what would signify that the process was killed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期情话 2024-09-01 17:08:26

中的 Process.Kill() 源代码显示将退出代码设置为 -1(截至 2012 年 9 月)。 Windows 操作系统实际上使用 32 位无符号值作为退出代码,但我相信 C# 中的有符号 -> 无符号 -> 有符号翻译应该可以工作(我只需要检查零或非零,所以它不会对我的代码很重要)。

另一方面,这显然是未记录的行为(为什么?),因此微软明天可以更改它并通过将退出代码设置为 0 来破坏我的代码。

The source code for Process.Kill() in shows setting the exit code to -1 (as of Sep 2012). The Windows operating system actually uses 32-bit unsigned values for the exit codes but I believe the signed->unsigned->signed translations in C# should work (I only need to check for zero or non-zero so it doesn't matter for my code).

On the other hand, this is obviously undocumented behavior (Why?) so Microsoft could change it tomorrow and break my code by setting the exit code to 0.

白芷 2024-09-01 17:08:26

您可以使用 ExitCode 属性,但不幸的是这取决于应用程序的构建方式。因此,如果您有应用程序的源代码,请确保它在正常退出时正确返回。请参阅 msdn 链接,更详细地描述这一点:
http://msdn.microsoft.com/en-us /library/system.diagnostics.process.exitcode.aspx

You can use the property ExitCode but unfortunately this depends on how the app is built. So if you have the source code for the app make sure that it returns correctly upon a good exit. Please see this link to msdn describing this more in detail:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文