Home > Net >  Child process not terminating when main process ends
Child process not terminating when main process ends

Time:01-20

I create a process using CreateProcessW. This process has a GUI (not a console application), so I execute WaitForInputIdle after the process is created. I see the window pop up, so I'm quite sure this part works.

When I then terminate the main process (CTRL C), the child process that was created keeps existing. Am I missing an option somewhere? Is this normal behaviour? I would like all the children processes to terminate as soon as the main one exits.

CodePudding user response:

When I then terminate the main process (CTRL C), the child process that was created keeps existing.

This is normal behavior.

Am I missing an option somewhere?

No.

Is this normal behaviour?

Yes.

I would like all the children processes to terminate as soon as the main one exits.

The best option would be to have the parent communicate with its children. If the parent is told to exit gracefully, it can notify its children to exit before it then exits. If the children lose communication with their parent, they can just exit themselves.

If that is not an option, then consider adding the parent and children to a Job Object, and then terminate the Job.

  • Related