Problem in "Process.waitFor()" in multithreaded application (UNIX OS)
Hello all
This is very urgent for me.
I am using the follwing code to invoke the child process which calls a shell script in the unix OS,and it is going fine when runs in single thread. But if i run it as the multhreaded appln, anyone of the thread hangs in the 'Process.waitfor()' call. But sometimes all the threads are returning successfully. I am calling this code from the one or more threads. This is tested in the java1.2 and 1.3. so can u suggest me how to change the code or any way to fix up the problem.
// the code starts
{
String s[] = new String[3];
s[0] = "/bin/sh";
s[1] = "-c";
s[2] = "encrypt.sh"; //some .sh filename to do the task
Runtime runtime = Runtime.getRuntime();
Process proc;
proc = runtime.exec(s);
//
InputStream is = proc.getInputStream();
byte buf[] = new byte[256];
int len;
while( (len=is.read(buf)) != -1) {
String s1 = new String(buf,0,len);
System.out.println(s1);
}
InputStream es = proc.getErrorStream();
buf = new byte[256];
while( (len=es.read(buf)) != -1) {
String s1 = new String(buf,0,len);
System.out.println("Error Stream : " + s1);
}
// place where it hang
retValue = proc.waitFor();
}
//code ends
i am handling the errorstream and output stream and not getting any error stream output and not printing any messages in the child process. When i synchronize the whole function, it went fine, but spoils the speed performance. I tried all the option but i could not solve the problem.
thanks

