From 6cbd5be8b6dcf39432d42b69d92b5c06906b83d6 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Tue, 27 Oct 2020 12:40:38 +0100 Subject: [PATCH] Killed or crashed daemon process kept in the registry until mvnd --stop is called #154 --- .../jboss/fuse/mvnd/client/DefaultClient.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java b/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java index 8ac630281..c373594c9 100644 --- a/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java +++ b/client/src/main/java/org/jboss/fuse/mvnd/client/DefaultClient.java @@ -154,13 +154,20 @@ public ExecutionResult execute(ClientOutput output, List argv) { final String template = " %36s %7s %5s %7s %5s %23s %s"; output.accept(null, String.format(template, "UUID", "PID", "Port", "Status", "RSS", "Last activity", "Java home")); - registry.getAll().forEach(d -> output.accept(null, String.format(template, - d.getUid(), d.getPid(), d.getAddress(), d.getState(), - OsUtils.kbTohumanReadable(OsUtils.findProcessRssInKb(d.getPid())), - LocalDateTime.ofInstant( - Instant.ofEpochMilli(Math.max(d.getLastIdle(), d.getLastBusy())), - ZoneId.systemDefault()), - d.getJavaHome()))); + for (DaemonInfo d : registry.getAll()) { + if (ProcessHandle.of(d.getPid()).isEmpty()) { + /* The process does not exist anymore - remove it from the registry */ + registry.remove(d.getUid()); + } else { + output.accept(null, String.format(template, + d.getUid(), d.getPid(), d.getAddress(), d.getState(), + OsUtils.kbTohumanReadable(OsUtils.findProcessRssInKb(d.getPid())), + LocalDateTime.ofInstant( + Instant.ofEpochMilli(Math.max(d.getLastIdle(), d.getLastBusy())), + ZoneId.systemDefault()), + d.getJavaHome())); + } + } return new DefaultResult(argv, null); } boolean stop = args.remove("--stop");