开发者

Exit code of a process terminated with Process.Kill() , in C#

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 开发者_如何学JAVAcan 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜