MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / get_pid_by_command

Method get_pid_by_command

mod/project/python/serviceMod.py:218–237  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

216 return None
217
218 def get_pid_by_command(self) -> Optional[int]:
219 cmd_list = self.split_command()
220 target = []
221 for p in psutil.process_iter(["cmdline", "pid", "exe"]):
222 try:
223 real_cmd = p.cmdline()
224 if cmd_list == real_cmd:
225 target.append(p)
226 if real_cmd[2:] == cmd_list[1:] and real_cmd[0].startswith(self.env.python_path):
227 target.append(p)
228 except:
229 continue
230
231 for p in target:
232 try:
233 if p.ppid() not in target:
234 return p.pid
235 except:
236 continue
237 return None
238
239 def split_command(self) -> List[str]:
240 res = []

Callers 2

get_service_pidMethod · 0.95
get_pid_by_commandMethod · 0.45

Calls 2

split_commandMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected