Creating independent process!

喜欢而已 提交于 2019-12-02 02:27:00

After closing thread and process handlers of the child process, it's still a child in the Process Explorer, but ending parent process doesn't cause termination of the child one.

CreateProcess( NULL,
            szCmdLine,
           NULL,
           NULL,
           FALSE,
           CREATE_NEW_PROCESS_GROUP,
           NULL,        
           NULL,        
           &si,        
           &pi ); 
if(pi.hThread)
    CloseHandle(pi.hTread);
if(pi.hProcess)
    CloseHandle(pi.hProcess);

I've found this decision in sources of cmd.exe of the ReactOS, in the procedure of executing 'start' command.

Create an intermediate process (use create_new_process_group), which then creates the real process.

Service
  -> Intermediate Process
     -> Real Process

The Intermediate process should exit as soon as it's launched the real process.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!