的Process.Start()和Process树 [英] Process.Start() and the Process Tree

查看:183
本文介绍了的Process.Start()和Process树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用的Process.Start(),但启动的过程中不要在同一个进程树的启动过程?

How can I use Process.Start(), but have the launched process not in the same process tree as the launching process?

考虑这个示例控制台应用程序:

Consider this sample console application:

using System;
using System.Diagnostics;
using System.Threading;

internal class Program
{
    private static void Main(string[] args)
    {
        Console.WriteLine("Starting ie...");
        Process.Start("c:\\Program Files\\Internet Explorer\\iexplore.exe", "http://www.google.com");
        Console.WriteLine("Waiting for 15 seconds");
        Thread.Sleep(15000);
        Console.WriteLine("Exiting...");
    }
}

在此程序正常退出,Internet Explorer将继续运行。但是,如果在15秒的睡眠阶段,你去任务管理器,并选择该程序,然后选择结束进程树,IE浏览器也将关闭。

When this program exits normally, Internet Explorer will continue to run. However, if during the 15 second sleep period you go to Task Manager and select this program and select "End Process Tree", Internet Explorer will also close.

(这直接关系到<一href="http://stackoverflow.com/questions/1033483/windows-xp-screen-saver-launched-process-dies-with-screen-saver">my从今天早些时候这个问题,到目前为止,还没有任何回复。在Windows XP中,当屏幕保护程序过程结束,这似乎结束进程树,而在Vista中,仅仅是屏幕保护程序结束。)

(This is directly related to my question from earlier today that, as yet, has no replies. In Windows XP, when the screen saver process ends, it appears to end the process tree, whereas in Vista, just the screen saver process is ended.)

推荐答案

Eric是正确的:Windows不公开更改流程父母的任何方法。然而,如果父母去世,没有链接回祖父母这样你就可以实现与中间的过程,开始孩子自己的目标,然后死。

Eric is correct: Windows does not expose any method of changing a processes parent. However, if the parent dies, there is no link back to grandparent so you can achieve your goal with an intermediate process that starts the child, then dies.

所以:PROC A开始PROC B,然后PROC B开始PROC C和立即死亡。当PROC B死,PROC C会遭到的进程树一个根节点 - PROCç将不会在进程内A的树PROC B死后

So: Proc A starts proc B, then proc B starts proc C and immediately dies. When proc B dies, proc C will be a root node on the process tree - proc C will NOT be in proc A's tree after proc B dies.

这篇关于的Process.Start()和Process树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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