如何创建一个不是其创建过程的子过程的过程? [英] How to create a process that is not a child of it's creating process?

查看:117
本文介绍了如何创建一个不是其创建过程的子过程的过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个进程,A和B.在某个时候A创建了B.创建B之后,如果A的进程 tree 被杀死,我希望B仍然存在.

我正在使用CreateProcess()创建B,并且在没有子进程的情况下,我似乎找不到任何使它创建进程的方法.与ShellExecuteEx()相同,但是我可能缺少一些标志.

有人知道我可以用来做什么吗?

我忘了提到两个进程都需要一个HANDLE或另一个进程的ID

解决方案

您可以尝试使用流程A创建流程C,该流程先创建流程B,然后流程C将立即终止(终止).在进程B中,仅存在有关直接父进程(不再运行的C的进程ID)的信息,而不是有关进程A的信息.因此,如果A的进程树被杀死",进程B可能会保持运行状态. /p>

例如,您启动Process Explorer(请参阅 http://technet.microsoft .com/en-us/sysinternals/bb896653.aspx ),然后启动Total Commander.从Total Commander中启动cmd.exe.从cmd.exe,启动notepad.exe.然后在cmd.exe中键入退出".终止cmd.exe后,您会看到notepad.exe将不再在Total Commander(totalcmd.exe)下显示.在Process Explorer的杀死进程树"中选择Total Commander(totalcmd.exe)之后,您可以看到notepad.exe保持运行.

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.

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?

EDIT: I forgot to mention that both processes need a HANDLE or process ID to the other

解决方案

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.

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.

这篇关于如何创建一个不是其创建过程的子过程的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆