How to create a process that is not a child of it#39;s creating process?(如何创建一个不是其创建过程的子进程?)
问题描述
我有两个进程,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.
这篇关于如何创建一个不是其创建过程的子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何创建一个不是其创建过程的子进程?
基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01