Process.getXXStream().close hangs

  • Thread starter Girish Betadpur
  • Start date
G

Girish Betadpur

Hi,
I start a new child process using Runtime.getRuntime().exec(). I have
taken care of all the necessary handling of the input and output streams
(in different streams).

Before I destroy the child process with Process.destroy(), I am trying to
close the standard streams of this external process. When I invoke
Process.getXXXStream().close(), the method hangs and I see that the child
java process consumes 100% CPU. Even after the parent process has died,
the child process continues to run with 100% CPU usage.
This is on Windows 2K/XP, Sun JDK 1.4.2.

Has anybody faced a similar problem? Is it illegal to close the standard
streams of an external process? Or is it required on some platforms?

Thanks,
Girish
 
G

Gordon Beaton

Before I destroy the child process with Process.destroy(), I am
trying to close the standard streams of this external process. When
I invoke Process.getXXXStream().close(), the method hangs and I see
that the child java process consumes 100% CPU. Even after the parent
process has died, the child process continues to run with 100% CPU
usage. This is on Windows 2K/XP, Sun JDK 1.4.2.

Has anybody faced a similar problem? Is it illegal to close the
standard streams of an external process? Or is it required on some
platforms?

Exactly how a process behaves when it reaches EOF on any of its
standard streams is entirely up to the process itself.

Most processes will terminate when they reach EOF on stdin, so you
should be able to close the streams without any problems. Maybe you
just need to close them in the right order. And once the child has
terminated, there is really no reason to call Process.destroy().

If closing stdin doesn't cause the child to terminate on its own, try
calling Process.destroy() *before* closing the streams. Or look into
using a different mechanism to terminate the child (e.g. does it read
commands on stdin?).

/gordon
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top