YARN-10490. yarn top command not quitting completely with ctrl+c. Contributed by Agshin Kazimli

This commit is contained in:
Szilard Nemeth 2021-01-21 20:30:19 +01:00
parent e2f8503ebd
commit 1ccba3734d

View File

@ -444,6 +444,7 @@ public TopCLI() throws IOException, InterruptedException {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
TopCLI topImp = new TopCLI(); TopCLI topImp = new TopCLI();
topImp.addShutdownHook();
topImp.setSysOutPrintStream(System.out); topImp.setSysOutPrintStream(System.out);
topImp.setSysErrPrintStream(System.err); topImp.setSysErrPrintStream(System.err);
int res = ToolRunner.run(topImp, args); int res = ToolRunner.run(topImp, args);
@ -492,7 +493,6 @@ public int run(String[] args) throws Exception {
rmStartTime = getRMStartTime(); rmStartTime = getRMStartTime();
} }
} }
clearScreen();
return 0; return 0;
} }
@ -1220,4 +1220,11 @@ private String getCommandOutput(String[] command) throws IOException,
byte[] output = IOUtils.toByteArray(p.getInputStream()); byte[] output = IOUtils.toByteArray(p.getInputStream());
return new String(output, "ASCII"); return new String(output, "ASCII");
} }
private void addShutdownHook() {
//clear screen when the program exits
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
clearScreen();
}));
}
} }