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

  • Home
  • SEARCH
  • 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 953313
In Process

The Archive Base Latest Questions

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

I have parent process that opens child process . I need to perform some

  • 0

I have parent process that opens child process . I need to perform some functionality only when the parent process is no more running.

What is the best way to know that the parent process is not running ? Because it can be terminated violently then I don’t want to make some functionality that will send signal to my child process on the closing event.

Or just looking for my parent process like that:

In the parent make this and pass it to the child Process.GetCurrentProcess().Id
And in the child every several milliseconds check this one

Process localById = Process.GetProcessById(1234);

Any ideas ? Recommendations ..

  • 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-16T00:02:01+00:00Added an answer on May 16, 2026 at 12:02 am

    Here is a simple example how to use Process.WaitForExit to check for a parent process whose id has been passed on the command line:

    using System;
    using System.Diagnostics;
    using System.Threading;
    
    class Program
    {
        static AutoResetEvent _autoResetEvent;
    
        static void Main(string[] args)
        {
            int parentProcessId = int.Parse(args[0]);
    
            _autoResetEvent = new AutoResetEvent(false);
    
            WaitCallback callback = delegate(object processId) { CheckProcess((int)processId); };
            ThreadPool.QueueUserWorkItem(callback, parentProcessId);
    
            _autoResetEvent.WaitOne();
        }
    
        static void CheckProcess(int processId)
        {
            try
            {
                Process process = Process.GetProcessById(processId);
                process.WaitForExit();
                Console.WriteLine("Process [{0}] exited.", processId);
            }
            catch (ArgumentException)
            {
                Console.WriteLine("Process [{0}] not running.", processId);
            }
    
            _autoResetEvent.Set();
        }
    }
    

    Using the Process.Exited event could be done like this:

    using System;
    using System.Diagnostics;
    using System.Threading;
    
    class Program
    {
        static AutoResetEvent _autoResetEvent;
    
        static void Main(string[] args)
        {
            int parentProcessId = int.Parse(args[0]);
            Process process = Process.GetProcessById(parentProcessId);
            process.EnableRaisingEvents = true;
            process.Exited += new EventHandler(process_Exited);
    
            _autoResetEvent = new AutoResetEvent(false);
            _autoResetEvent.WaitOne();
        }
    
        static void process_Exited(object sender, EventArgs e)
        {
            Console.WriteLine("Process exit event triggered.");
            _autoResetEvent.Set();
        }
    }
    

    Note that in both samples the purpose of the AutoResetEvent is solely to prevent your main thread from exiting. In a Windows Forms application you would not need to use it as your program will be in a message loop and only exit if you close it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try updating the ItemContainerStyle as follows: <ListBox x:Name="listBox"> <ListBox.ItemContainerStyle> <Style… May 16, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer Not good to bind to a port. Try starting the… May 16, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer found it: have to specify the key file location manually:… May 16, 2026 at 11:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a parent object called Page that has a List of objects called
What a mouthful. Basically I have a parent <div> and inside that an <iframe>
In APUE section 8.3 fork function , about file sharing between parent and child
I would like to create a file whose descriptor would have some customizable behavior.
I've written a two short programs that use anonymous pipes to communicate. The parent
I have a ListView with different layouts for different items. Some items are separators.
I have parent project with: <modules> <module>../module1</module> <module>../module2</module> <module>../module3</module> </modules> and modules with <parent>
When I have a parent Entity hold a list of other entity (one to
Python's subprocess module by default passes all open file descriptors to any child processes
I'm working on some Python code modeled on Apache's MPM prefork server. I am

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.