From 1ccba3734d1c46aaae1cd3dd4dd504e691771167 Mon Sep 17 00:00:00 2001 From: Szilard Nemeth Date: Thu, 21 Jan 2021 20:30:19 +0100 Subject: [PATCH] YARN-10490. yarn top command not quitting completely with ctrl+c. Contributed by Agshin Kazimli --- .../java/org/apache/hadoop/yarn/client/cli/TopCLI.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/TopCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/TopCLI.java index 79b1406ed1..882d2bfce2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/TopCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/TopCLI.java @@ -444,6 +444,7 @@ public TopCLI() throws IOException, InterruptedException { public static void main(String[] args) throws Exception { TopCLI topImp = new TopCLI(); + topImp.addShutdownHook(); topImp.setSysOutPrintStream(System.out); topImp.setSysErrPrintStream(System.err); int res = ToolRunner.run(topImp, args); @@ -492,7 +493,6 @@ public int run(String[] args) throws Exception { rmStartTime = getRMStartTime(); } } - clearScreen(); return 0; } @@ -1220,4 +1220,11 @@ private String getCommandOutput(String[] command) throws IOException, byte[] output = IOUtils.toByteArray(p.getInputStream()); return new String(output, "ASCII"); } + + private void addShutdownHook() { + //clear screen when the program exits + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + clearScreen(); + })); + } }