CreateProcess创建子进程,WaitForSingleObject等待子进程退出,都没问题现在情况是子进程可能又启动了其他进程,我需要等所有子进程退出后WaitForSingleObject才返回,该怎么处理?

解决方案 »

  1.   

    让子进程也WaitForSingleObject等待它的子进程退出
      

  2.   

    道理一样吧,子进程也要用WaitForSingleObject等待子子进程初始化结束
      

  3.   

    最标准的方法:使用作业(Job)对象。http://msdn.microsoft.com/en-us/library/windows/desktop/ms684161(v=vs.85).aspx
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms684847(v=vs.85).aspx#job_object_functionsWindows系统中使用“作业”来管理一组相关进程。A job object allows groups of processes to be managed as a unit. Job objects are namable, securable, shareable objects that control attributes of the processes associated with them. Operations performed on a job object affect all processes associated with the job object. Examples include enforcing limits such as working set size and process priority or terminating all processes associated with a job.