Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

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 using 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?

like image 221
Aseem Bansal Avatar asked Oct 14 '22 19:10

Aseem Bansal


1 Answers

  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.

like image 80
Hans Passant Avatar answered Nov 15 '22 08:11

Hans Passant