apacay
apacay

Reputation: 1712

How to suicide a console app?

I have a Console App which creates/launches other sub-processes. I need to check somehow if itself or his ProcessChilds are went to deadlock, and kill the youngest of the associated process tree.

With this objective, his process childs, may have the same "kind of recursive" algorithm.

The idea is not to kill the youngest process but instead to get the youngest to suicide by command (in a sort of speak).

Is there a way I can call an async method inside the process (maybe the same method that should exist in his childs) to do that?

Well of course I could use a persistent file and a "WatchDog/KeepAliveLook" of that file and when it does not exist anymore they do it (suicide) but I'm convinced there's a cleaner way to do this.

Upvotes: 1

Views: 171

Answers (2)

Dai
Dai

Reputation: 155005

If a process is entirely deadlocked, then you can't use any of its threads. You would need to (externally) create a new thread within the process, something which can only be done with Windows' debugging APIs.

If you want to kill a child process, why not kill it directly rather than asking it to kill itself?

Upvotes: 0

Daniel P. Bullington
Daniel P. Bullington

Reputation: 643

I would use some method of inter-proccess communication (remoting, WCF, named pipes, window events, DDE, etc) to send the notification to "eat a poison pill". The bigger question is why are you designing this as such? Sounds a bit archaic and antiquated architecture.

Upvotes: 2

Related Questions