Z
zyng
Hi:
I am using the following code to call a system command
final ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"/bin/sh", "-c", the_command_and_arguments});
final Process processRunSysCmd = processBuilder.start();//start a new process -- a child process
I have learned that I need to drain the output of the external command (input stream to the parent process -- the java program) in case that it has too much output and the buffer is saturated. In that case, the program will hang.
But when I think deeper, I am puzzled: there are two processes running now(one is the one i called "parent process", another is the child process). Since each one is single threaded, may I say there are two threads right now?!
So if I don't drain the output of the child process, and too much output and buffer saturated, the parent process will hang?! Will the child process hang too? Or both processes hang? Since they are two threads, so one thread cause another thread hang?
Thank you.
I am using the following code to call a system command
final ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"/bin/sh", "-c", the_command_and_arguments});
final Process processRunSysCmd = processBuilder.start();//start a new process -- a child process
I have learned that I need to drain the output of the external command (input stream to the parent process -- the java program) in case that it has too much output and the buffer is saturated. In that case, the program will hang.
But when I think deeper, I am puzzled: there are two processes running now(one is the one i called "parent process", another is the child process). Since each one is single threaded, may I say there are two threads right now?!
So if I don't drain the output of the child process, and too much output and buffer saturated, the parent process will hang?! Will the child process hang too? Or both processes hang? Since they are two threads, so one thread cause another thread hang?
Thank you.