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

Method get_pid_by_env_key

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

Source from the content-addressed store, hash-verified

196 return None
197
198 def get_pid_by_env_key(self) -> Optional[int]:
199 env_key = "BT_PYTHON_SERVICE_SID={}".format(self.sid)
200 target = []
201 for p in psutil.pids():
202 try:
203 data: str = public.readFile("/proc/{}/environ".format(p))
204 if data.rfind(env_key) != -1:
205 target.append(p)
206 except:
207 continue
208
209 for i in target:
210 try:
211 p = psutil.Process(i)
212 if p.ppid() not in target:
213 return i
214 except:
215 continue
216 return None
217
218 def get_pid_by_command(self) -> Optional[int]:
219 cmd_list = self.split_command()

Callers 1

get_service_pidMethod · 0.95

Calls 3

readFileMethod · 0.80
formatMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected