Freigeben über


how to get the parent of a Process

Well, today's challange is to find a way to obtain a process' parent...if it has one.  We have a situation where a test executable may or may not be launched by a test harness.  If it is, I'm told that the test harness should show up as the test executables parent.  So I figured that would be a good way to determine if the test executable was launched by a harness or not.

So far, all my MSN searches have yielded little in the way of a solution.  I'm fairly sure I'll have to marshall some kind of Win32 api or something, which is fine...but I don't know which one I'll need.  :)

Can anyone point me in the right direction?

Comments

  • Anonymous
    July 20, 2005
    Have you looked at Process Explorer from Sysinternals?
    http://www.sysinternals.com/Utilities/ProcessExplorer.html
  • Anonymous
    July 20, 2005
    I have, and that's a great tool. It's what I used to find out that Process.Modules doesn't contain the information I'm looking for, hehehe. What I need is a way to do this programatically. :)
  • Anonymous
    July 20, 2005
    Win32_Process in WMI has pretty much everything about system processes.
  • Anonymous
    July 20, 2005
    In general, there is no reliable way to determine a process's parent; only realiably find its children. In your case if you can know that the test harness that might have spawned your test is still running you might be able to tell who the parent was. If you really want to go this route, use WMI like Nicholas suggested, but be aware that it may be unreliable.
    Looking at this from another angle - do you also own the harness? Then you could tell reliably from the harness-side.
    Another possibilty (though kinda flaky) would be to launch your test differently than it would be launched if not from the harness. Pass some special argument into the test, maybe?
  • Anonymous
    June 27, 2006
    The comment has been removed
  • Anonymous
    June 30, 2006
    Asaspal. Memrano tu es besta. Amigo.