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 9e5743eaf0..f7a9991a08 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(); } /**