Re: Terminating a process tree

From: Gordon Beaton (not_at_for.email)
Date: 11/09/04


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


Relevant Pages

  • Re: Terminating a process tree
    ... >> I'm not sure how I would achieve this under Windows. ... >> I dont know how under windows to get the PID of an application using ... > stream in the parent process, effectively signalling EOF to the child. ... > the loop that feeds commands through a queue of objects to the other ...
    (comp.lang.java.programmer)
  • Re: problem with rand on OSX
    ... Each child has a different $slp on my system. ... because the children explicitly break out of the loop with $pid set to ... $pid is used in a loop in the parent, but at the end of the loop, it's ...
    (comp.lang.perl.misc)
  • Re: MDI child and tool widows - always on top?
    ... I think you may try to run the code in the Child Form's Form_Load event, then the embeded form will on the child form only. ... Based on my research, the other floating windows, including the toolbar of VS.NET IDE will not have hightlight when we click on it. ... isn't showing on top of the 'parent' MDI child at all. ... Perhaps the best way would be to loop through the MDI children and see if the contact window exists. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Killing a process that takes too long
    ... You may instead use fork and exec; this lets you use the process-ID to ... kill 'INT', $pid; ... and it does not guarantee that the child ... So we need a way to kill several processes of the process group of the parent, ...
    (perl.beginners)
  • Re: SBCL just turned 1.0!
    ... Lisp implementation means either lazyness or technical incompetence ... "Return any available status information on child processed. ... (multiple-value-bind (pid status) ... ;; Terminate the child process. ...
    (comp.lang.lisp)