开发者

A Process is refusing to die

开发者 https://www.devze.com 2023-01-17 09:20 出处:网络
Based on other questions, I\'m using System.Diagnostics.Process to Start and Kill a process: this.childProcess.Kill();

Based on other questions, I'm using System.Diagnostics.Process to Start and Kill a process:

this.childProcess.Kill();
this.childProcess.WaitForExit();
this.childProcess.Close();

I would assume that WaitForExit deals with the asynchronous nature of the Kill c开发者_开发知识库ommand, however the process in question (perl.exe) refuses to die. Instead it lingers for some period of time.

This "period of time" is causing a race condition. Is there anyway I can make sure this process actually dies?


I'm not sure what you mean by "make sure this process actually dies." Under the hood the Kill method eventually calls TerminateProcess which is the most effective way to kill a process and WaitForExit won't return until the process is actually gone.

The Kill method can fail to actually kill the process in at least 2 circumstances

  1. You don't have sufficient rights to kill the process
  2. There is a debugger attached to the process (I believe this prevents TerminateProcess from working).
  3. Uninterruptable I/O operation (thanks Daniel)

Do either of these apply to your scenario?

0

精彩评论

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