code: def test_raylet_graceful_exit_upon_runtime_env_agent_exit(
      ray_start_cluster,
  ):
      cluster = ray_start_cluster
      # head
      cluster.add_node(num_cpus=0)
  
      def get_raylet_runtime_env_agent_procs(worker):
          raylet = None
          for p in worker.live_processes():
              if p[0] == "raylet":
                  raylet = p[1]
          assert raylet is not None
  
          children = psutil.Process(raylet.pid).children()
          target_path = os.path.join("runtime_env", "agent", "main.py")
          for child in children:
              if target_path in " ".join(child.cmdline()):
                  return raylet, child
          raise ValueError("runtime env agent not found")
  
      # Make sure raylet exits gracefully upon agent terminated by SIGTERM.
      worker = cluster.add_node(num_cpus=0)
      raylet, agent = get_raylet_runtime_env_agent_procs(worker)
      agent.terminate()
      exit_code = raylet.wait()
      # When the agent is terminated
      assert exit_code == 0
  
      # Make sure raylet exits gracefully upon agent terminated by SIGKILL.
      # TODO(sang): Make raylet exits ungracefully in this case. It is currently
      # not possible because we cannot detect the exit code of children process
      # from cpp code.
      worker = cluster.add_node(num_cpus=0)
      raylet, agent = get_raylet_runtime_env_agent_procs(worker)
      agent.kill()
      exit_code = raylet.wait()
      # When the agent is terminated
      assert exit_code == 0
  
imports: import sys
  import time
  import platform
  import os
  import signal
  import multiprocessing
  import pytest
  import ray
  import psutil
  from ray._private.test_utils import wait_for_condition, run_string_as_driver_nonblocking
  from ray.util.state import get_worker, list_tasks
  from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy
label_desc: Use image node_id 12 for calling a global function with example usage: test_raylet_graceful_exit_upon_runtime_env_agent_exit(ray_start_cluster) and returns: raylet,  child