Return (ppid, pgid, state) for a live non-zombie process.
(pid)
| 125 | |
| 126 | |
| 127 | def process_identity(pid): |
| 128 | """Return (ppid, pgid, state) for a live non-zombie process.""" |
| 129 | result = subprocess.run( |
| 130 | [ |
| 131 | "ps", |
| 132 | "-p", |
| 133 | str(pid), |
| 134 | "-o", |
| 135 | "ppid=", |
| 136 | "-o", |
| 137 | "pgid=", |
| 138 | "-o", |
| 139 | "stat=", |
| 140 | ], |
| 141 | stdout=subprocess.PIPE, |
| 142 | stderr=subprocess.DEVNULL, |
| 143 | text=True, |
| 144 | check=False, |
| 145 | ) |
| 146 | if result.returncode != 0: |
| 147 | return None |
| 148 | try: |
| 149 | ppid, pgid, state = result.stdout.split(None, 2) |
| 150 | if state.startswith("Z"): |
| 151 | return None |
| 152 | return int(ppid), int(pgid), state |
| 153 | except (TypeError, ValueError): |
| 154 | return None |
| 155 | |
| 156 | |
| 157 | def worker_tree_identity_matches( |
no test coverage detected