problem killing nested Runtime.getRuntime().exec() processes

B

bugbear

In a shell-out I'm having a problem.

Having done far too much reading, I have separate
threads reading stdout, stderr, and a timeout thread
ensuring that my shell out doesn't take too long.

(I'm using external code for some batch processing).

If the process takes too long, the timeout
thread hits proc.destroy() on the "main" thread.

This works well.

I recently discovered that a "batch" process I was
using is itself a wrapper script (call it "parent")
that calls the "real code" (call it "infinite")

The real code, as you may have guessed, went
infinite.

My timeout code killed the "parent" thread, and
then my 2 stdout/stderr emptying threads ... waited.

Sadly, the infinite process does *NOT* die, and since
it inherited stdout and stderr from its parent, my emptyer
threads don't terminate. Bizarrely, the infinite process
then had a parent process Id of 1.

My speculation is that Java is using a kill(2) system call.
http://linux.ctyme.com/man/man1333.htm
Sadly, I suspect that Java is using the positive pid
entry point, whereas I suspect it should be sending
in the negative pid.

Has anyone else seen this, know a cure or workround?

BugBear
 
B

bugbear

bugbear said:
In a shell-out I'm having a problem.
My timeout code killed the "parent" thread, and
then my 2 stdout/stderr emptying threads ... waited.

Sadly, the infinite process does *NOT* die, and since
it inherited stdout and stderr from its parent, my emptyer
threads don't terminate. Bizarrely, the infinite process
then had a parent process Id of 1.

I found no solution such that the calling java
could kill all child processes. Indeed, from reading
it appears that my naive idea of "child processes"
is itself incomplete.

In the end, the workround was:
Top level called process turns itself into a process group.
http://www.cs.ucsb.edu/~almeroth/classes/W99.276/assignment1/signals.html

Then, when the top level called process catches
a TERM signal, it kills it's own group,
and then exits.

I hope this information is of use to someone.

BugBear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top