Skip to content

Commit 1ccba37

Browse files
YARN-10490. yarn top command not quitting completely with ctrl+c. Contributed by Agshin Kazimli
1 parent e2f8503 commit 1ccba37

File tree

1 file changed

+8
-1
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli

1 file changed

+8
-1
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/TopCLI.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public TopCLI() throws IOException, InterruptedException {
444444

445445
public static void main(String[] args) throws Exception {
446446
TopCLI topImp = new TopCLI();
447+
topImp.addShutdownHook();
447448
topImp.setSysOutPrintStream(System.out);
448449
topImp.setSysErrPrintStream(System.err);
449450
int res = ToolRunner.run(topImp, args);
@@ -492,7 +493,6 @@ public int run(String[] args) throws Exception {
492493
rmStartTime = getRMStartTime();
493494
}
494495
}
495-
clearScreen();
496496
return 0;
497497
}
498498

@@ -1220,4 +1220,11 @@ private String getCommandOutput(String[] command) throws IOException,
12201220
byte[] output = IOUtils.toByteArray(p.getInputStream());
12211221
return new String(output, "ASCII");
12221222
}
1223+
1224+
private void addShutdownHook() {
1225+
//clear screen when the program exits
1226+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
1227+
clearScreen();
1228+
}));
1229+
}
12231230
}

0 commit comments

Comments
 (0)