code: def terminate_process_tree(pid):
      process = psutil.Process(pid)
      children = process.children(recursive=True)
      children.append(process)
      for child in children:
          try:
              child.terminate()
          except psutil.NoSuchProcess:
              pass
      gone, alive = psutil.wait_procs(children, timeout=30)
      for p in alive:
          p.kill()
  
file_path: DeepSpeed/deepspeed/launcher/launch.py
imports: import sys
  import subprocess
  import os
  import json
  import base64
  import time
  import signal
  import psutil
  from collections import defaultdict
  from typing import Dict
  from argparse import ArgumentParser, REMAINDER
  from ..constants import TORCH_DISTRIBUTED_DEFAULT_PORT
  from ..nebula.constants import DLTS_POD_ENV_PATH
  from ..utils import logger, get_numactl_cmd
  from ..elasticity import is_torch_elastic_compatible
  from .constants import ELASTIC_TRAINING_ID_DEFAULT
label_desc: Use image node_id 2 for calling a global function with example usage: terminate_process_tree(pid) without return types