code: def get_remote_pids(ip, port, cmd_regex):
      """Get the process IDs that run the command in the remote machine."""
      pids = []
      curr_pid = os.getpid()
      # Here we want to get the python processes. We may get some ssh processes, so we should filter them out.
      ps_cmd = (
          "ssh -o StrictHostKeyChecking=no -p "
          + str(port)
          + " "
          + ip
          + " 'ps -aux | grep python | grep -v StrictHostKeyChecking'"
      )
      res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE)
      for p in res.stdout.decode("utf-8").split("\n"):
          l = p.split()
          if len(l) < 2:
              continue
          # We only get the processes that run the specified command.
          res = re.search(cmd_regex, p)
          if res is not None and int(l[1]) != curr_pid:
              pids.append(l[1])
  
      pid_str = ",".join([str(pid) for pid in pids])
      ps_cmd = (
          "ssh -o StrictHostKeyChecking=no -p "
          + str(port)
          + " "
          + ip
          + " 'pgrep -P {}'".format(pid_str)
      )
      res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE)
      pids1 = res.stdout.decode("utf-8").split("\n")
      all_pids = []
      for pid in set(pids + pids1):
          if pid == "" or int(pid) == curr_pid:
              continue
          all_pids.append(int(pid))
      all_pids.sort()
      return all_pids
  
imports: import argparse
  import json
  import logging
  import multiprocessing
  import os
  import queue
  import re
  import signal
  import subprocess
  import sys
  import time
  from functools import partial
  from threading import Thread
  from typing import Optional
label_desc: Use image node_id 5 for calling a global function with example usage: get_remote_pids(ip, port, cmd_regex) and returns: all_pids