MCPcopy
hub / github.com/dmlc/dgl / get_remote_pids

Function get_remote_pids

tools/launch.py:155–193  ·  view source on GitHub ↗

Get the process IDs that run the command in the remote machine.

(ip, port, cmd_regex)

Source from the content-addressed store, hash-verified

153
154
155def get_remote_pids(ip, port, cmd_regex):
156 """Get the process IDs that run the command in the remote machine."""
157 pids = []
158 curr_pid = os.getpid()
159 # Here we want to get the python processes. We may get some ssh processes, so we should filter them out.
160 ps_cmd = (
161 "ssh -o StrictHostKeyChecking=no -p "
162 + str(port)
163 + " "
164 + ip
165 + " 'ps -aux | grep python | grep -v StrictHostKeyChecking'"
166 )
167 res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE)
168 for p in res.stdout.decode("utf-8").split("\n"):
169 l = p.split()
170 if len(l) < 2:
171 continue
172 # We only get the processes that run the specified command.
173 res = re.search(cmd_regex, p)
174 if res is not None and int(l[1]) != curr_pid:
175 pids.append(l[1])
176
177 pid_str = ",".join([str(pid) for pid in pids])
178 ps_cmd = (
179 "ssh -o StrictHostKeyChecking=no -p "
180 + str(port)
181 + " "
182 + ip
183 + " 'pgrep -P {}'".format(pid_str)
184 )
185 res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE)
186 pids1 = res.stdout.decode("utf-8").split("\n")
187 all_pids = []
188 for pid in set(pids + pids1):
189 if pid == "" or int(pid) == curr_pid:
190 continue
191 all_pids.append(int(pid))
192 all_pids.sort()
193 return all_pids
194
195
196def get_all_remote_pids(hosts, ssh_port, udf_command):

Callers 1

get_all_remote_pidsFunction · 0.70

Calls 6

searchMethod · 0.80
appendMethod · 0.80
formatMethod · 0.80
runMethod · 0.45
decodeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected