ADDITIONAL SYSTEM INFORMATION :
ProductName: Mac OS X
ProductVersion: 10.15.1
BuildVersion: 19B88
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
A DESCRIPTION OF THE PROBLEM :
I use process execute a command [tail -f test.log | grep test]ï¼Âwhen i call destroy, only stop the parent process, but the child process not stop.
REGRESSION : Last worked in version 8
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
code :
public static void main(String[] args) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder()
.directory(new File("/Users/leix.xie/logs"))
.redirectErrorStream(true)
.command("/bin/bash", "-c", "tail -f test.txt|stdbuf -o0 grep 1");
final Process process = processBuilder.start();
InputStream stream = process.getInputStream();
byte[] bytes = new byte[1024];
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
process.destroyForcibly();
System.out.println("destroy");
}
}).start();
while (true) {
int read = stream.read(bytes);
if (read == -1) {
break;
}
System.out.println(Arrays.copyOfRange(bytes, 0, read));
}
}
run the method of main
the java process will start 3 process in the os
501 5760 5758 0 12:04ä¸Âå ?? 0:00.00 /bin/bash -c tail -f test.txt|stdbuf -o0 grep 1
501 5761 5760 0 12:04ä¸Âå ?? 0:00.00 tail -f test.txt
501 5762 5760 0 12:04ä¸Âå ?? 0:00.00 grep 1
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
6000ms later, I hope the three process has been stoped
ACTUAL -
501 5761 1 0 12:04ä¸Âå ?? 0:00.00 tail -f test.txt
501 5762 1 0 12:04ä¸Âå ?? 0:00.00 grep 1
only the parent process stoped
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
/**
* @author leix.xie
* @date 2019/11/11 11:38
* @describe
*/
public class ProcessTest {
public static void main(String[] args) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder()
.directory(new File("/Users/leix.xie/logs"))
.redirectErrorStream(true)
.command("/bin/bash", "-c", "tail -f test.txt|stdbuf -o0 grep 1");
final Process process = processBuilder.start();
InputStream stream = process.getInputStream();
byte[] bytes = new byte[1024];
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
process.destroyForcibly();
System.out.println("destroy");
}
}).start();
while (true) {
int read = stream.read(bytes);
if (read == -1) {
break;
}
System.out.println(Arrays.copyOfRange(bytes, 0, read));
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
i have no workaround
FREQUENCY : always
ProductName: Mac OS X
ProductVersion: 10.15.1
BuildVersion: 19B88
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
A DESCRIPTION OF THE PROBLEM :
I use process execute a command [tail -f test.log | grep test]ï¼Âwhen i call destroy, only stop the parent process, but the child process not stop.
REGRESSION : Last worked in version 8
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
code :
public static void main(String[] args) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder()
.directory(new File("/Users/leix.xie/logs"))
.redirectErrorStream(true)
.command("/bin/bash", "-c", "tail -f test.txt|stdbuf -o0 grep 1");
final Process process = processBuilder.start();
InputStream stream = process.getInputStream();
byte[] bytes = new byte[1024];
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
process.destroyForcibly();
System.out.println("destroy");
}
}).start();
while (true) {
int read = stream.read(bytes);
if (read == -1) {
break;
}
System.out.println(Arrays.copyOfRange(bytes, 0, read));
}
}
run the method of main
the java process will start 3 process in the os
501 5760 5758 0 12:04ä¸Âå ?? 0:00.00 /bin/bash -c tail -f test.txt|stdbuf -o0 grep 1
501 5761 5760 0 12:04ä¸Âå ?? 0:00.00 tail -f test.txt
501 5762 5760 0 12:04ä¸Âå ?? 0:00.00 grep 1
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
6000ms later, I hope the three process has been stoped
ACTUAL -
501 5761 1 0 12:04ä¸Âå ?? 0:00.00 tail -f test.txt
501 5762 1 0 12:04ä¸Âå ?? 0:00.00 grep 1
only the parent process stoped
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
/**
* @author leix.xie
* @date 2019/11/11 11:38
* @describe
*/
public class ProcessTest {
public static void main(String[] args) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder()
.directory(new File("/Users/leix.xie/logs"))
.redirectErrorStream(true)
.command("/bin/bash", "-c", "tail -f test.txt|stdbuf -o0 grep 1");
final Process process = processBuilder.start();
InputStream stream = process.getInputStream();
byte[] bytes = new byte[1024];
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
process.destroyForcibly();
System.out.println("destroy");
}
}).start();
while (true) {
int read = stream.read(bytes);
if (read == -1) {
break;
}
System.out.println(Arrays.copyOfRange(bytes, 0, read));
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
i have no workaround
FREQUENCY : always