17 """General utility functions."""
24 def find_os_processes(name):
25 """Find all the processes that are running gz sim."""
26 ps_output = subprocess.check_output([
'ps',
'aux'], text=
True)
27 ps_lines = ps_output.split(
'\n')
31 columns = line.split()
33 command =
' '.join(columns[10:])
34 if command.startswith(name):
35 gz_sim_processes.append((pid, command))
36 return gz_sim_processes
39 def kill_process(pid):
40 """Kill a process with a given PID."""
42 os.kill(int(pid), signal.SIGKILL)
43 print(f
'Successfully killed process with PID: {pid}')
44 except Exception
as e:
45 print(f
'Failed to kill process with PID: {pid}. Error: {e}')
48 def kill_os_processes(name):
49 """Kill all processes that are running with name."""
50 processes = find_os_processes(name)
52 for pid, _
in processes:
55 print(f
'No processes found starting with {name}')