Reputation: 25
I have a java app that calls a ksh script that is hanging. A look on the backend shows that the script's write process to STDOUT
is full and blocked. STDERR
is supposed to be empty and my java code is reading that first. Debugging shows the java app hangs reading the STDERR
inputstream which in turn causes the script process attempting to write more to STDOUT to become blocked. I think STDERR
is being written to second(after STDOUT
), so it just waits until it sees input(and it can't receive input because write is stuck on STDOUT
).
This app works fine on multiple Linux boxes(all identical OS and kernels) except for one. Putting each inputstream read in separate threads resolves the issue on this one box. I know the linux default for STDERR
is nonbufferring and that input usually is written to that immediately. So I'm thinking that STDERR
might be set to buffered on this box. How/Where do I find the value of that?
Upvotes: 0
Views: 181
Reputation: 53694
Reading stderr and stdout with a single thread is a bad idea, case in point. the correct solution is to use two separate threads. anything else is just a race condition waiting to fail.
maybe you are confusing non-buffering with non-blocking? making stderr non-buffering will not remove the possibility that your program could hang at any point in time (by blocking on stderr or sdout).
Upvotes: 1