kill child process on restart of my windows  service

Posted on 2011-05-10
Last Modified: 2012-06-21
I have created a windows service which fires another process (myprocess.exe) every 10 minutes, which creates files, prints them and exits. Sometimes when someone restarts the service while myprocess is still running, it does not kill the myprocess in the memory. The service starts another myprocess.exe, and now I see two instances of myprocess.exe in the task manager. Since both are trying to write to the same file, they clash and I get error.

How do I make my service kill myprocess.exe, if it is running when the service gets restarted.

Question by:patd1
    LVL 6

    Accepted Solution

    You could check if the process myprocess.exe is running when the service restarts. If it exists, you could kill it.


    Read the comments.

    Author Comment

    Thanks that was what I was thinking, but wanted to make sure if that is the right thing to do. Does it matter if I kill the myprocess onStop instead of onStart.

    Thank You.
    LVL 6

    Expert Comment

    It doesn't matter, but make sure you kill the process before you start the new process.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now