12 Replies Latest reply on Mar 22, 2011 7:29 PM by YoungWinston

    How to stop/kill child process?

    848469
      I am creating one process, and it will call another exe.
      Now both are running as a different process. When I am closing my application first process is destroyed by calling destroy method. But I can’t able to close second process.


      Thanks in advance.
        • 1. Re: How to stop/kill child process?
          baftos
          java.util.Process.destroy()
          1 person found this helpful
          • 2. Re: How to stop/kill child process?
            848469
            Thanks for reply.

            I'm not creating the second process. it will be created by the first process. i know only second process name.

            Using process name(eg: a.exe) i want to kill/destroy that process.


            Thanks once again.
            • 3. Re: How to stop/kill child process?
              EJP
              You will have to get the first process to destroy the 2nd. More appropriately you should arrange things so that both processes exit, rather than being killed.
              • 4. Re: How to stop/kill child process?
                848469
                hi EJP,

                Thanks for your reply.

                Both are third party exe. the first one will call automatically second one.

                I am creating process only for first exe. i don't have control over second exe.
                • 5. Re: How to stop/kill child process?
                  darrylburke
                  Cross posted
                  http://www.java-forums.org/new-java/40923-how-kill-child-process.html

                  db
                  • 6. Re: How to stop/kill child process?
                    EJP
                    Both are third party exe. the first one will call automatically second one.
                    In that case you should rely on whatever the first process does about the second, and you should rely on the first process to exit cleanly. Or else you are doing something odd that the authors of the processes may not have intended. Why do you have to kill these processes?
                    • 7. Re: How to stop/kill child process?
                      848469
                      thanks,

                      I have started my application by calling the first exe, then it will call second .exe.

                      when i close my application it is destroying first .exe it is not destroying the second one. Due to this when i run my app once again it is showing your application already running.
                      • 8. Re: How to stop/kill child process?
                        EJP
                        when i close my application it is destroying first .exe
                        Why? Surely there is a way of making it exit cleanly, taking its sub-process with it?
                        • 9. Re: How to stop/kill child process?
                          YoungWinston
                          User845466 wrote:
                          I have started my application by calling the first exe, then it will call second .exe.
                          when i close my application it is destroying first .exe it is not destroying the second one. Due to this when i run my app once again it is showing your application already running.
                          Sounds to me like you need to talk to the people that supplied you with this. Either they intended for it to be killable (in which case process 1 should deal with its child gracefully) or they didn't, in which case you're trying to do something naughty. But only they can give you that information.

                          Winston
                          • 10. Re: How to stop/kill child process?
                            dadams07
                            Actually, java.*lang*.Process...
                            • 11. Re: How to stop/kill child process?
                              jschellSomeoneStoleMyAlias
                              User845466 wrote:
                              thanks,

                              I have started my application by calling the first exe, then it will call second .exe.

                              when i close my application it is destroying first .exe it is not destroying the second one. Due to this when i run my app once again it is showing your application already running.
                              This isn't a java problem at this point.

                              You have your "first exe".
                              You have your "second exe".

                              There are two possibilities.
                              1. There is something in "first exe" that allows it to terminate the "second exe"
                              2. There is no way to do that.

                              You must determine which of those it is. And that process has nothing to do with java.

                              If you determine that it is 1, then with that information you can then look to java to see if there is a way to invoke that. You cannot attempt to solve it with java however UNTIL you have the information.

                              If it is 2 then you are left with finding an OS specific way to do the following.
                              1. Locate the 'process' of the "second exe"
                              2. Use 'process' to kill "second exe"

                              Those steps have nothing to do with java. However once you know what those steps are it will be possible, but perhaps not easy, to implement via java (although still with OS specific functionality.)
                              • 12. Re: How to stop/kill child process?
                                YoungWinston
                                jschell wrote:
                                This isn't a java problem at this point.
                                If it is 2 then you are left with finding an OS specific way to do the following.
                                1. Locate the 'process' of the "second exe"
                                2. Use 'process' to kill "second exe"
                                The only thing I will add to that is that any extra-Java method you use better leave the system in a consistent state. Kill -9 (the preferred method of old on Unix systems, simply because it's (almost) guaranteed to do its job) has caused more problems than I've had hot dinners; and I disallow it as a matter of course on all systems that I administer (even for me).

                                Winston