Get the process IDs that we want to kill but are still alive.
(ip, port, killed_pids)
| 74 | |
| 75 | |
| 76 | def get_killed_pids(ip, port, killed_pids): |
| 77 | """Get the process IDs that we want to kill but are still alive.""" |
| 78 | killed_pids = [str(pid) for pid in killed_pids] |
| 79 | killed_pids = ",".join(killed_pids) |
| 80 | ps_cmd = ( |
| 81 | "ssh -o StrictHostKeyChecking=no -p " |
| 82 | + str(port) |
| 83 | + " " |
| 84 | + ip |
| 85 | + " 'ps -p {} -h'".format(killed_pids) |
| 86 | ) |
| 87 | res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE) |
| 88 | pids = [] |
| 89 | for p in res.stdout.decode("utf-8").split("\n"): |
| 90 | l = p.split() |
| 91 | if len(l) > 0: |
| 92 | pids.append(int(l[0])) |
| 93 | return pids |
| 94 | |
| 95 | |
| 96 | def execute_remote( |