0

I want to start a random child process and let it run even if the parent process exit later.

It should be possible to read the standard output in none-blocking manner from the child process even if the parent has exited. Another proces should be able to reconnect and read the standard output from the running child process.

I have achieved all that in Unix with mkfifo and open with C Programming Language .

I have achieved almost the same in Windows with CreateNamedPipeA , CreateFile and CreateProcess.

But in Windows when the parent process exit, i don't know how to reconnect to the already running child process so i can read the standard output instead of starting a new child process.

Can someone please guide me on how to do that in Windows? if that even is possible.

  • when parent exit, it pipe end closed. child pipe end is broken. all write/read to it will fail after this. you can not reconnect to pipe without child will be special design to this (close broken pipe and create new, or if it is server end - disconnect and listen again) – RbMm Oct 18 '20 at 23:40
  • The pipe in Unix is a special file, and the system will not automatically delete this pipe. In windows, the pipe resource is controlled by the system(as @RbMm said). You may need to redirect the output of the child process to a file(like unix pipe file), open and read this file in the loop. – Drake Wu Oct 19 '20 at 04:12
  • Thank you to both! @RbMm it seems like it not possible to reconnect to the same pipe and still get output from the random child process that previously was started with CreateProcess so there is no code logic to re-force connection i guess... - @ Drake Wu Do you know how I can redirect the output of the child process to a file in WIndows? – Hans Hansen Oct 19 '20 at 06:23
  • [This sample](https://stackoverflow.com/a/16256188/10611792) works for me to redirect the output to a file. – Drake Wu Oct 19 '20 at 07:36
  • 1
    A pipe is also a special file in Windows, in the named-pipe filesystem (NPFS). Each pipe file in NPFS has a File Control Block (FCB) that gets set in the `FsContext` field of the [file object](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_file_object) for all instances of the pipe. However, the data queues for a pipe instance are in the Context Control Block (CCB) that's shared by the server/client file objects for a particular instance, which is set in the `FsContext2` field of their respective file objects. An instance can't be reconnected. – Eryk Sun Oct 19 '20 at 07:51
  • @DrakeWu-MSFT Thank you! i'm going try that – Hans Hansen Oct 19 '20 at 08:01
  • @ErykSun Thank you for explaining that and confirming the connection part ! - Big thanks to all of you!! – Hans Hansen Oct 19 '20 at 08:01

0 Answers0