<commit_before>#!/usr/bin/env bash
# Common utils
set -o nounset

# kill the process with retry
# return 0 if kill succeeds or no process to kill,
#        1 if kill fails

function kill_process_with_retry {
   pid="$1"
   pname="$2"
   maxattempt="$3"

   if [[ -z $pid ]]; then
     echo "pid doesn't exist, shutdown completed"
     return 0
   fi

   for try in $(seq 1 $maxattempt); do
     if [[ ! -z $pid ]]; then
      echo "Killing $pname. [pid: $pid], attempt: $try"
      kill ${pid}
      sleep 5
      if [[ -n "$(ps -p $pid -o pid=)" ]]; then
        echo "$pname is not dead [pid: $pid]"
        if [[ $try -lt $maxattempt ]]; then
          echo "sleeping for a few seconds before retry"
          sleep 10
        fi
      else
        echo "shutdown succeeded"
        return 0
      fi
     fi
    done

   echo "Error: unable to kill process for $maxattempt attempt(s), shutdown failed"
   return 1
}<commit_msg>Shutdown the process with kill -9 at the end in shutdown scripts (#941)<commit_after>#!/usr/bin/env bash
# Common utils
set -o nounset

# kill the process with retry
# return 0 if kill succeeds or no process to kill,
#        1 if kill fails

function kill_process_with_retry {
   pid="$1"
   pname="$2"
   maxattempt="$3"

   if [[ -z $pid ]]; then
     echo "pid doesn't exist, shutdown completed"
     return 0
   fi

   for try in $(seq 1 $maxattempt); do
     if [[ ! -z $pid ]]; then
      echo "Killing $pname. [pid: $pid], attempt: $try"
      kill ${pid}
      sleep 5
      if [[ -n "$(ps -p $pid -o pid=)" ]]; then
        echo "$pname is not dead [pid: $pid]"
        if [[ $try -lt $maxattempt ]]; then
          echo "sleeping for a few seconds before retry"
          sleep 10
        fi
      else
        echo "shutdown succeeded"
        return 0
      fi
     fi
    done

   echo "Error: unable to kill process for $maxattempt attempt(s), killing the process with -9"
   kill -9 $pid
   sleep 5
   if [[ -n "$(ps -p $pid -o pid=)" ]]; then
      echo "$pname is not dead even after kill -9 [pid: $pid]"
      return 1
   else
    echo "shutdown succeeded"
    return 0
   fi
}

{'fraction_non_alphanumeric': 0.1156015037593985, 'fraction_numerical': 0.01550751879699248, 'mean_word_length': 2.0899854862119014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2474624', 'n_tokens_mistral': 728, 'n_tokens_neox': 675, 'n_words': 284}