0

I have a thread in some console process, whose code is not available to me. Is there a way to get notified when its state changes (e.g. becomes idle)?

Maybe hooks API or even kernel-mode API (if no other way...)?

Expansion:

I have legacy console app I have to operate in my program. The only way to interact with it, obviously, is via stdin. So I run it as new Process, and send commands to its stdin. I take some text from its stdout, but it is not entirely predictable, so I cannot rely on it in order to know when it finished its current work and ready to receive the next commands. The flow is something like this: I run it, send (e.g.) command1, wait for it to finish its work (some CPU load and some IO operations), and then issue command2, and so on, until last command. When it finished working on last command, I can close it gracefully (send exit command). The thing is that I have several processes of this console exe that are working simultaneously.

I can:

  1. use timeouts since last stdout received - not good, because it can be a millisecond and an hour
  2. parse stdout using (e.g.) regex to wait for expected outputs - not good... the output is wholly unexpected. It's almost random
  3. using timers, poll its threads state and only when all of them are in wait state (and not for IO), and at least one is waiting for user input (see this) - not good either: in case I use many processes simultaneously it can create unnecessary, non-proportional burden on the system.

So I like the last option, just instead polling, I rather events fired when these threads become idle.

I hope it explains the issue well...

Community
  • 1
  • 1
Tar
  • 8,529
  • 9
  • 56
  • 127
  • What is your actual goal? – David Heffernan Apr 22 '15 at 12:55
  • @DavidHeffernan, to know when the process is idle (not doing any computation/IO-operation/printing-text/whatever...) and just waiting for input - just not by polling, only event-driven. – Tar Apr 22 '15 at 13:00
  • Why do you want to know that? I suspect that your proposed solution to your problem is the wrong solution. But since we don't know the problem, it's hard to say. – David Heffernan Apr 22 '15 at 13:03
  • @DavidHeffernan I think the problem is pretty straightforward... I want to be notified when the process finished its work and waiting for input (threads are in wait state, one or more of then is/are waiting on the process's `stdin`). Again - not by polling. – Tar Apr 22 '15 at 13:09
  • Given the response you've had at both of your attempts to ask this question, I'd say that the question needs more work. It's very likely that your proposed solution is the wrong one. However, you don't seem at all interested in explaining the problem, so be it. Good luck. – David Heffernan Apr 22 '15 at 13:14
  • @DavidHeffernan, there's another option: it's not possible... That's how it seems... – Tar Apr 22 '15 at 13:17
  • You are not listening to me. I give up. – David Heffernan Apr 22 '15 at 13:24
  • @DavidHeffernan, I added detailed explanation. Hope it clears the purpose – Tar Apr 24 '15 at 11:40

0 Answers0