Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
bugbear - 02 Nov 2005 17:51 GMT
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
bugbear - 04 Nov 2005 13:11 GMT
> In a shell-out I'm having a problem.
> My timeout code killed the "parent" thread, and
[quoted text clipped - 4 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.