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

Function get_remote_pids

tools/distgraphlaunch.py:137–175  ·  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

135
136
137def get_remote_pids(ip, port, cmd_regex):
138 """Get the process IDs that run the command in the remote machine."""
139 pids = []
140 curr_pid = os.getpid()
141 # Here we want to get the python processes. We may get some ssh processes, so we should filter them out.
142 ps_cmd = (
143 "ssh -o StrictHostKeyChecking=no -p "
144 + str(port)
145 + " "
146 + ip
147 + " 'ps -aux | grep python | grep -v StrictHostKeyChecking'"
148 )
149 res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE)
150 for p in res.stdout.decode("utf-8").split("\n"):
151 l = p.split()
152 if len(l) < 2:
153 continue
154 # We only get the processes that run the specified command.
155 res = re.search(cmd_regex, p)
156 if res is not None and int(l[1]) != curr_pid:
157 pids.append(l[1])
158
159 pid_str = ",".join([str(pid) for pid in pids])
160 ps_cmd = (
161 "ssh -o StrictHostKeyChecking=no -p "
162 + str(port)
163 + " "
164 + ip
165 + " 'pgrep -P {}'".format(pid_str)
166 )
167 res = subprocess.run(ps_cmd, shell=True, stdout=subprocess.PIPE)
168 pids1 = res.stdout.decode("utf-8").split("\n")
169 all_pids = []
170 for pid in set(pids + pids1):
171 if pid == "" or int(pid) == curr_pid:
172 continue
173 all_pids.append(int(pid))
174 all_pids.sort()
175 return all_pids
176
177
178def 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