开发者

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

In have 2 processes, a parent process and a child process. The parent process controls the lifecycle of child process i.e. parent process launches the child process when it needs the child to do some work and also it kills the child when it is done with it. To kill the child process, parent process is u开发者_如何学Pythonsing Process.Kill() and process.WaitForExit() APIs.

Questions: -

  1. I am observing that the exit code of the child process is always -1. Who is setting this exit code?

  2. How can I change this exit code?


  1. Process.Kill
  2. No. Unless you pinvoke TerminateProcess() yourself, uExitCode argument.

Have a look at Reflector, this kind of stuff is easy to find with it.


The process exit code is likely being set by Win32. You can't change it. If you want to change the exit code, don't use Process.Kill as your IPC mechanism. Set an event or use other IPC primitives instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜