Re: Terminating a process tree
From: Wayne Marrison (wayne_at_wmcomputing.com)
Date: 11/09/04
- Next message: Thomas Weidenfeller: "Re: Listeners and Events"
- Previous message: Gleb: "Re: Crystal Reports and Java"
- In reply to: Gordon Beaton: "Re: Terminating a process tree"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 9 Nov 2004 12:06:44 -0000
"Gordon Beaton" <not@for.email> wrote in message
news:4190afa0$1@news.wineasy.se...
> On Tue, 9 Nov 2004 11:34:46 -0000, Wayne Marrison wrote:
>> I'm not sure how I would achieve this under Windows. I have looked
>> at calling the "kill.exe" or the "taskkill.exe" directly, but then
>> fall into the trap of trying to get the PID of the command I have
>> just started. I know there are suggestions on using JNI to achieve
>> that, but the learning curve is too great for me at this point.
>>
>> I dont know how under windows to get the PID of an application using
>> batch/script commands .. maybe I'd best rethink this as the
>> complexities are starting to outweigh the benefits.
>
> How does the child process behave when its stdin is closed?
>
> A simple way to "kill" the process is to close the corresponding
> stream in the parent process, effectively signalling EOF to the child.
>
> The child could have a main loop that does nothing but this:
>
> while ((in = System.in.read()) > 0); // empty loop body
> System.exit(0);
>
> Put the rest of the child's logic in a separate thread.
>
> If the child actually needs to handle input from stdin, add logic to
> the loop that feeds commands through a queue of objects to the other
> thread, so that any hang won't prevent the loop from exiting when
> stdin closes.
>
> /gordon
>
> --
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
The problem here is that the command I'm trying to control is not written by
myself - its seperate. I have my other threads (the ones that are
controlling the input/output streams to this external app) operating as far
as I can see, correctly. They are closed before I ask the external app to
close (tried it the other way round too, just to make sure) but the act of,
or attempting to forcibly destroy the hung application is not working.
I think the art of closing a working application is quite simple, as you
say, closing the input stream usually works. But if the application is in
an unknown, perhaps hung state, what I thought would terminate it
(proc.destroy()) isnt.
Wayne
- Next message: Thomas Weidenfeller: "Re: Listeners and Events"
- Previous message: Gleb: "Re: Crystal Reports and Java"
- In reply to: Gordon Beaton: "Re: Terminating a process tree"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|