开发者

Determine Child Processes for Thread or Appdomain

开发者 https://www.devze.com 2022-12-12 22:26 出处:网络
I\'m using a开发者_如何学Go 3rd party assembly to do some processing, and it spawns 2 child processes to perform some work. I\'m running this in a separate thread.

I'm using a开发者_如何学Go 3rd party assembly to do some processing, and it spawns 2 child processes to perform some work. I'm running this in a separate thread.

I want to be able to cancel the processing if it runs for too long - my problem is that if I abort the thread the spawned processes are still running.

Is there a way to determine what processes were spawned by a specific thread so I can kill them?

I can perform the work in a separate Appdomain if that would help any - is there a way to determine what processes were spawned within a specific Appdomain?

Notes

  • I have no way of getting the process IDs from the 3rd party assembly
  • I cannot simply kill all processes matching a name, as I will be running a few of these worker threads concurrently (and if one runs too long I only want to kill the processes spawned in that thread)
  • I know it's 'safe' for me to just kill these processes


If the third party assembly doesn't provide you a callback or some way to determine that a process is spawned with a given PID so that you can keep track of them, there's no way to find out that a process has been spawned from a given thread in your application. The closest you might get is the command line used to run the process.


I figured out a workaround - when a worker thread is aborted the processes it has spawned are 'orphaned' (the parent process ID is no longer than of my application), so I can determine which processes to kill that way.

0

精彩评论

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