njnu-seafish commented on code in PR #17320:
URL: 
https://github.com/apache/dolphinscheduler/pull/17320#discussion_r2192010050


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/utils/ProcessUtils.java:
##########
@@ -144,18 +156,54 @@ public static boolean kill(@NonNull TaskExecutionContext 
request) {
      */
     private static boolean sendKillSignal(String signal, String pids, String 
tenantCode) {
         try {
+            // 1. Send the kill signal
             String killCmd = String.format("kill -s %s %s", signal, pids);
             killCmd = OSUtils.getSudoCmd(tenantCode, killCmd);
             log.info("Sending {} to process group: {}, command: {}", signal, 
pids, killCmd);
             OSUtils.exeCmd(killCmd);
 
+            // 2. Wait for the process to respond to the signal
+            ThreadUtils.sleep(SLEEP_TIME_MILLIS * PROCESS_STATUS_CHECK_DELAY);

Review Comment:
    The logic for 'kill' already exists:
              
               // 1. Try to terminate gracefully (SIGINT)
               boolean gracefulKillSuccess = sendKillSignal("SIGINT", pids, 
request.getTenantCode());
               if (gracefulKillSuccess) {
                   log.info("Successfully killed process tree using SIGINT, 
processId: {}", processId);
                   return true;
               }
   
               // 2. Try to terminate forcefully (SIGTERM)
               boolean termKillSuccess = sendKillSignal("SIGTERM", pids, 
request.getTenantCode());
               if (termKillSuccess) {
                   log.info("Successfully killed process tree using SIGTERM, 
processId: {}", processId);
                   return true;
               }
   
               // 3. As a last resort, use `kill -9`
               log.warn("SIGINT & SIGTERM failed, using SIGKILL as a last 
resort for processId: {}", processId);
               boolean forceKillSuccess = sendKillSignal("SIGKILL", pids, 
request.getTenantCode());
               if (forceKillSuccess) {
                   log.info("Successfully sent SIGKILL signal to process tree, 
processId: {}", processId);
               } else {
                   log.error("Error sending SIGKILL signal to process tree, 
processId: {}", processId);
               }
               return forceKillSuccess;



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to