From 4a1303b625f3425550636a522ad2e38bd8cae1b7 Mon Sep 17 00:00:00 2001 From: wenjun <861923274@qq.com> Date: Tue, 6 Apr 2021 10:47:53 +0800 Subject: [PATCH] [Improvement][Worker] Kill task error(#5199) (#5212) --- .../dolphinscheduler/server/utils/ProcessUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java index 9e5743eaf..f7a9991a0 100644 --- a/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java +++ b/dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/utils/ProcessUtils.java @@ -409,7 +409,7 @@ public class ProcessUtils { * @throws Exception exception */ public static String getPidsStr(int processId) throws Exception { - StringBuilder sb = new StringBuilder(); + List pidList = new ArrayList<>(); Matcher mat = null; // pstree pid get sub pids if (OSUtils.isMacOS()) { @@ -424,11 +424,14 @@ public class ProcessUtils { if (null != mat) { while (mat.find()) { - sb.append(mat.group(1)).append(" "); + pidList.add(mat.group(1)); } } - return sb.toString().trim(); + if (CommonUtils.isSudoEnable() && !pidList.isEmpty()) { + pidList = pidList.subList(1, pidList.size()); + } + return String.join(" ", pidList).trim(); } /** -- GitLab