Re: Terminating a process tree
From: Gordon Beaton (not_at_for.email)
Date: 11/09/04
- Next message: Michael Borgwardt: "Re: Listeners and Events"
- Previous message: Wayne Marrison: "Re: Terminating a process tree"
- In reply to: Wayne Marrison: "Re: Terminating a process tree"
- Next in thread: Wayne Marrison: "Re: Terminating a process tree"
- Reply: Wayne Marrison: "Re: Terminating a process tree"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Nov 2004 12:53:04 +0200
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
- Next message: Michael Borgwardt: "Re: Listeners and Events"
- Previous message: Wayne Marrison: "Re: Terminating a process tree"
- In reply to: Wayne Marrison: "Re: Terminating a process tree"
- Next in thread: Wayne Marrison: "Re: Terminating a process tree"
- Reply: Wayne Marrison: "Re: Terminating a process tree"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|