From 2aa4209ba3d40974daf12bdb2962c95ce3f02743 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 11 Jan 2026 17:58:44 +0200 Subject: [PATCH] #3 Do not fail on parsing of ps output --- src/ltm/ProcessesPanel.java | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ltm/ProcessesPanel.java b/src/ltm/ProcessesPanel.java index bb54584..949a3f8 100644 --- a/src/ltm/ProcessesPanel.java +++ b/src/ltm/ProcessesPanel.java @@ -211,15 +211,19 @@ private void refreshProcesses() { tableModel.addRow(processInfo); } - // Calculate CPU and Memory percentages - double cpuPercentage = calculateCpuPercentage(processData) * 100; - double memoryPercentage = calculateMemoryPercentage(processData) * 100; - - // Update the CPU and Memory progress bars - cpuProgressBar.setValue((int) cpuPercentage); - cpuProgressBar.setString(String.format("CPU: %.0f%%", cpuPercentage)); - memoryProgressBar.setValue((int) memoryPercentage); - memoryProgressBar.setString(String.format("Memory: %.0f%%", memoryPercentage)); + try { + // Calculate CPU and Memory percentages + double cpuPercentage = calculateCpuPercentage(processData) * 100; + double memoryPercentage = calculateMemoryPercentage(processData) * 100; + + // Update the CPU and Memory progress bars + cpuProgressBar.setValue((int) cpuPercentage); + cpuProgressBar.setString(String.format("CPU: %.0f%%", cpuPercentage)); + memoryProgressBar.setValue((int) memoryPercentage); + memoryProgressBar.setString(String.format("Memory: %.0f%%", memoryPercentage)); + } catch (Exception e) { + e.printStackTrace(); + } // Wait for the process to complete int exitCode = process.waitFor(); @@ -227,7 +231,7 @@ private void refreshProcesses() { // Handle any errors if necessary System.err.println("Error executing script. Exit code: " + exitCode); } - } catch (IOException | InterruptedException e) { + } catch (Exception e) { e.printStackTrace(); } }