code: def get_top_n_memory_usage(n: int = 10):
      """Get the top n memory usage of the process
  
      Params:
          n: Number of top n process memory usage to return.
      Returns:
          (str) The formatted string of top n process memory usage.
      """
      pids = psutil.pids()
      proc_stats = []
      for pid in pids:
          try:
              proc = psutil.Process(pid)
              proc_stats.append(
                  (get_rss(proc.memory_info()), pid, proc.cmdline())
              )
          except psutil.NoSuchProcess:
              # We should skip the process that has exited. Refer this
              # issue for more detail:
              # https://github.com/ray-project/ray/issues/14929
              continue
          except psutil.AccessDenied:
              # On MacOS, the proc_pidinfo call (used to get per-process
              # memory info) fails with a permission denied error when used
              # on a process that isn’t owned by the same user. For now, we
              # drop the memory info of any such process, assuming that
              # processes owned by other users (e.g. root) aren't Ray
              # processes and will be of less interest when an OOM happens
              # on a Ray node.
              # See issue for more detail:
              # https://github.com/ray-project/ray/issues/11845#issuecomment-849904019  # noqa: E501
              continue
      proc_str = "PID\tMEM\tCOMMAND"
      for rss, pid, cmdline in sorted(proc_stats, reverse=True)[:n]:
          proc_str += "\n{}\t{}GiB\t{}".format(
              pid,
              round(rss / (1024**3), 2),
              " ".join(cmdline)[:100].strip(),
          )
      return proc_str
  
file_path: ray/python/ray/_private/memory_monitor.py
imports: import logging
  import os
  import platform
  import sys
  import time
  import ray
  import psutil
label_desc: Use image node_id 3 for calling a global function with example usage: get_top_n_memory_usage(n) and returns: proc_str