0

Ok question is simple. I create a child process in a parent process. They are communicating with pipeline but that is not important. I want to detect if my child process closed, interupted, or may be throw an exception. Basicaly i want to control my child process. But in search of 2 days i couldn't find any way to do it in WINDOWS and i am getting frustrated to google about getting same "linux" solutions. None of the solutions in stackoverflow, given below, works for me.

Send messages from child process to parent

How can I send messages (or signals) from a parent process to a child process and viceversa in Perl?

send signal from parent process to child in C

Sending signals between parent and child process

Community
  • 1
  • 1
  • AFAIK, processes in Windows work on seperate spaces, not much hierarchy there like Linux does; so there is no "direct" way of doing it. You must implement (or use APIs like OpenMP or such) in order to do this. I might be mistaken though. – Ahmet Ipkin Apr 13 '16 at 09:43
  • You are asking for 2 different things: First you say, that you want to **monitor** a child process, but then you move on and want to **control** a child process. Which one is it now? – IInspectable Apr 13 '16 at 09:53
  • @AhmetIpkin yes, i realize in these 2 days about ther aren't any direct solution. May be "check process id" etc. – ömer Deveci Apr 13 '16 at 10:25
  • @IInspectable i think i am looking for **monitoring** child process signals. For example, i want to see an output in parent console when i hit ctrl + c in child console. – ömer Deveci Apr 13 '16 at 10:25
  • So you want to get notified, when your child process terminated in any way? In that case, simply [WaitForSingleObject](https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032.aspx) on the child process handle. It'll get signaled when the process terminated. – IInspectable Apr 13 '16 at 10:29
  • @IInspectable thanks man, that's what i look for. Also this thread answers my question, i think i should google it "sub process" not "child process" :D http://stackoverflow.com/questions/9369823/how-to-get-a-sub-process-return-code – ömer Deveci Apr 13 '16 at 10:47
  • Neither *child process* nor *sub process* is meaningful in Windows. While child-parent-relations are recorded by the system, they aren't being used for anything. There are only processes. To control groups of processes in Windows you would use [Job Objects](https://msdn.microsoft.com/en-us/library/windows/desktop/ms684161.aspx) instead, which allows finer grained control than a simple child-parent-relationship would. – IInspectable Apr 13 '16 at 10:53
  • I think the main problem is that this question is actually many questions. You are asking for a lot. As for "detect if my child process closed, interupted, or may be throw an exception" you get a handle and a process id in the PROCESS_INFORMATION for the process. I assume you know how to use that but if you ask a specific question about just that then you will get help, but be sure to search for previous answers first. If you ask specific questions then there is a good chance you will find existing answers. – Sam Hobbs Apr 13 '16 at 23:45

1 Answers1

0

Windows does not have the unix style process control (fork, wait, exec) or signaling (signal, kill, procmask).

Stian Skjelstad
  • 2,277
  • 1
  • 9
  • 19