Returns a list of dicts containing {pid, ppid, cmdline} for related processes.
(self)
| 482 | return result |
| 483 | |
| 484 | def __get_procs(self): |
| 485 | """ |
| 486 | Returns a list of dicts containing {pid, ppid, cmdline} for related processes. |
| 487 | """ |
| 488 | if self.container_id is not None: |
| 489 | container_info = get_container_info(self.container_id) |
| 490 | if container_info["State"]["Status"] != "running": |
| 491 | return [] |
| 492 | return [{'pid': container_info["State"]["Pid"], 'ppid': 0, 'cmdline': self.cmd}] |
| 493 | |
| 494 | # In non-containerised case, search for process based on matching command lines. |
| 495 | procs = [] |
| 496 | for process in psutil.process_iter(['pid', 'ppid', 'cmdline']): |
| 497 | # psutil changed behavior for process_iter() so that it no longer checks |
| 498 | # for reused pids. Use is_running() to do that. |
| 499 | if not process.is_running(): |
| 500 | continue |
| 501 | |
| 502 | # psutil returns None for fields from a zombie process |
| 503 | if not process.info['cmdline']: |
| 504 | continue |
| 505 | |
| 506 | # Use info because it won't throw NoSuchProcess exceptions. |
| 507 | if set(self.cmd) == set(process.info['cmdline']): |
| 508 | procs.append(process.info) |
| 509 | return procs |
| 510 | |
| 511 | def kill(self, signal=SIGKILL): |
| 512 | """ |
no test coverage detected