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

Discussion in 'Java' started by bugbear, Nov 2, 2005.

  1. bugbear

    bugbear Guest

    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, Nov 2, 2005
    #1
    1. Advertising

  2. bugbear

    bugbear Guest

    bugbear wrote:
    > 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
     
    bugbear, Nov 4, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zsolt Koppany
    Replies:
    2
    Views:
    7,238
    SaintMagoo
    Mar 5, 2011
  2. S!mb@
    Replies:
    3
    Views:
    7,714
    Roedy Green
    Jul 19, 2004
  3. Mao
    Replies:
    2
    Views:
    3,138
  4. Dave Neuendorf
    Replies:
    5
    Views:
    6,768
    Anthony Borla
    Feb 25, 2005
  5. Rohit Gupta
    Replies:
    1
    Views:
    3,507
    Sebastian Scheid
    Jun 16, 2005
Loading...

Share This Page