Find all child processes of my own .NET process / find out if a given process is a child of my own?

后端 未结 2 1085
离开以前
离开以前 2020-11-27 22:30

I have a .NET class library that spins up a secondary process which is kept running until I dispose of the object.

Due to some occurances of the program lingering in

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 22:54

    Although the answer of mtijn is probably the closest you can get, the real answer is: you can't.

    Windows does not maintain a real process tree where processes are re-structured when a process on an intermediate level dies. However, Windows does remember the parent process ID.

    The problematic case is the following:

    Original process structure:

    YourApp.exe
    - SubApp.exe
      - Second.exe
    

    If now SubApp.exe terminates, the parent process ID of Second.exe will not be updated. The new result is

    YourApp.exe
    Second.exe
    

    You can verify this using SysInternals Process Explorer. It is able to show the processes as a tree. Start CMD, then type start cmd. Into the new window, type start cmd again. You'll have 3 windows open. Now terminate the middle one.

提交回复
热议问题