Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top