Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:02:01+00:00 2026-05-25T03:02:01+00:00

I have a .NET class library that spins up a secondary process which is

  • 0

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 memory, I’ve decided to add an integration test to ensure that if I let the object lapse to GC/Finalization, that process is spun down.

However, since the process is the Mercurial command line client, and my build server is already running Mercurial as part of its own operations, I envision situations where Mercurial is either already running when that test starts, or that it is started, and is still running, when the test finishes, in relation to the build server, and not my test.

So, I want to make sure the Mercurial client I find (or not) is the one I started, and not just any client that is currently running.

So the question is this:

  • How can I find out if the Mercurial client I am looking at was started by my process?

By “looking at”, I was looking at using the Process.GetProcesses method, but this is not a requirement.

If a different question is better, “How to find all child processes of my own process”, ie. easier to answer, that one is more than enough as well.

I found this page: How I can know the parent process ID of a process?, but it seems that I have to give it the process name. If I just give it “hg”, isn’t that question too ambiguous for the case I’m looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:02:02+00:00Added an answer on May 25, 2026 at 3:02 am

    as it happens I have a bit of C#/WMI code lying around that kills all processes spawned by a specified process id, recursively. the killing is obviously not what you want, but the finding of child processes seems to be what you’re interested in. I hope this is helpful:

        private static void KillAllProcessesSpawnedBy(UInt32 parentProcessId)
        {
            logger.Debug("Finding processes spawned by process with Id [" + parentProcessId + "]");
    
            // NOTE: Process Ids are reused!
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(
                "SELECT * " +
                "FROM Win32_Process " +
                "WHERE ParentProcessId=" + parentProcessId);
            ManagementObjectCollection collection = searcher.Get();
            if (collection.Count > 0)
            {
                logger.Debug("Killing [" + collection.Count + "] processes spawned by process with Id [" + parentProcessId + "]");
                foreach (var item in collection)
                {
                    UInt32 childProcessId = (UInt32)item["ProcessId"];
                    if ((int)childProcessId != Process.GetCurrentProcess().Id)
                    {
                        KillAllProcessesSpawnedBy(childProcessId);
    
                        Process childProcess = Process.GetProcessById((int)childProcessId);
                        logger.Debug("Killing child process [" + childProcess.ProcessName + "] with Id [" + childProcessId + "]");
                        childProcess.Kill();
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assembly (.NET class library) that contains an object that implements EAP
I have a .NET class library containing a class with a method that performs
I have an ASP.NET VB.NET web project that references a VB.NET class library. I
I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have a C# .NET 2.0 project A (class library) that has a form
i have a winsock component made with vb.net in a class library that has
I have a class library that I have written in C#.net. I want to
I have a problem in a VB.Net class library which I have simplified greatly
I currently have a .NET class library written in C# that exposes its functionaility
I have a vb.net 3.5 class library project that needs to reference two assemblies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.