如何创建一个不是其创建过程的子进程?
我有两个进程,A 和 B.在某个时刻 A 创建 B.在创建 B 之后,如果 A 的进程 tree 被杀死,我希望 B 仍然存在.
I have two processes, A and B. At some point A creates B. After B is created, if A's process tree is killed, I want B to still be around.
我正在使用 CreateProcess() 来创建 B,但我似乎无法找到任何方法让它在没有孩子的情况下创建该进程.与 ShellExecuteEx() 相同,但我可能缺少一些标志.
I am using CreateProcess() to create B, and I can't seem to find any way to make it create the process without it being a child. Same thing with ShellExecuteEx(), but I am probably missing some flag.
有谁知道我可以用什么来做到这一点?
Does anyone know what I could use to do this?
我忘了提到两个进程都需要另一个进程的句柄或进程 ID
推荐答案
你可以试试A进程创建进程C,创建进程B然后进程C会立即结束(终止).在进程 B 中,仅存在有关直接父进程(C 的进程 ID 未运行)的信息,而不是有关进程 A 的信息.因此,如果 A 的进程树被杀死",则进程 B 可能会继续运行.
You can try that process A create process C, which create process B and then process C will be immediatly ended (terminated). In a process B there are exist only information about the direct parent process (process Id of C which is not more running) and not about the process A. So "if A's process tree is killed" the process B will probably stay running.
例如,您启动 Process Explorer(请参阅 http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) 然后启动 Total Commander.从 Total Commander 启动 cmd.exe.从 cmd.exe 启动 notepad.exe.然后在 cmd.exe 中键入exit".cmd.exe 终止后,您可以看到notepad.exe 将不再显示在Total Commander (totalcmd.exe) 下.在 Process Explorer 中为 Total Commander (totalcmd.exe) 选择Kill Process Tree"后,您可以看到 notepad.exe 仍在运行.
For example you start Process Explorer (see http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) then start Total Commander. From the Total Commander you start cmd.exe. From cmd.exe you start notepad.exe. Then type "exit" in the cmd.exe. After terminating of cmd.exe you can see that notepad.exe will no more displayed under Total Commander (totalcmd.exe). After you choose in Process Explorer "Kill Process Tree" for the Total Commander (totalcmd.exe) you can see that notepad.exe stay running.
相关文章