是否可以让控制台等待另一个 child 进程?
Is it possible to make a console wait on another child process?
通常当程序从Windows控制台运行时,控制台会等待进程退出然后打印提示,等待用户输入。但是,如果进程启动了一个child进程,控制台仍然只会等待第一个进程退出。它也不会等待 child。
程序是否有办法让控制台等待另一个 child 进程而不是(或同时)当前进程。
我认为这是不可能的,因为大概控制台正在等待进程的句柄并且没有办法替换该句柄。但是,我正在努力寻找对此的任何确认。
Is there a way for the program to get the console to wait on another child process instead of (or as well as) the current process.
没有。正如您所指出的,一旦控制台创建的第一个进程退出,控制台就会停止等待。它没有第一个进程创建的任何子进程的概念。
所以,您可以做的是:
让第一个进程等待它创建的任何子进程,然后退出。
如果这不是一个选项,则创建一个单独的辅助进程,在退出之前创建一个 Job Object and then starts the main process and assigns it to that job. Any child processes it creates will automatically be put into the same job as well 1. The helper process can then wait for all processes in the job to exit。然后,您可以使用控制台 运行 并等待辅助进程而不是主进程。
1:默认情况下 - 进程生成器可以选择从当前作业中分离出一个新的子进程,如果作业设置为允许的话。
通常当程序从Windows控制台运行时,控制台会等待进程退出然后打印提示,等待用户输入。但是,如果进程启动了一个child进程,控制台仍然只会等待第一个进程退出。它也不会等待 child。
程序是否有办法让控制台等待另一个 child 进程而不是(或同时)当前进程。
我认为这是不可能的,因为大概控制台正在等待进程的句柄并且没有办法替换该句柄。但是,我正在努力寻找对此的任何确认。
Is there a way for the program to get the console to wait on another child process instead of (or as well as) the current process.
没有。正如您所指出的,一旦控制台创建的第一个进程退出,控制台就会停止等待。它没有第一个进程创建的任何子进程的概念。
所以,您可以做的是:
让第一个进程等待它创建的任何子进程,然后退出。
如果这不是一个选项,则创建一个单独的辅助进程,在退出之前创建一个 Job Object and then starts the main process and assigns it to that job. Any child processes it creates will automatically be put into the same job as well 1. The helper process can then wait for all processes in the job to exit。然后,您可以使用控制台 运行 并等待辅助进程而不是主进程。
1:默认情况下 - 进程生成器可以选择从当前作业中分离出一个新的子进程,如果作业设置为允许的话。