1861
|
1 #!/usr/bin/env python3 |
|
2 |
|
3 import os |
|
4 import sys |
|
5 import time |
|
6 import psutil |
|
7 |
|
8 from pathlib import Path |
|
9 |
|
10 |
|
11 want_name = "dropbear" |
|
12 # Walks up the parent process tree, prints the first line of /proc/pid/maps when |
|
13 # it finds the wanted name |
|
14 |
|
15 def main(): |
|
16 |
|
17 try: |
|
18 for p in psutil.Process().parents(): |
|
19 print(p.pid, file=sys.stderr) |
|
20 print(p.name(), file=sys.stderr) |
|
21 print(p.cmdline(), file=sys.stderr) |
|
22 |
|
23 if want_name in p.name(): |
|
24 with (Path('/proc') / str(p.pid) / "maps").open() as f: |
|
25 map0 = f.readline().rstrip() |
|
26 print(map0) |
|
27 return |
|
28 |
|
29 raise RuntimeError(f"Couldn't find parent {want_name} process") |
|
30 except Exception as e: |
|
31 print(psutil.Process().parents()) |
|
32 for p in psutil.Process().parents(): |
|
33 print(p.name()) |
|
34 print(e) |
|
35 # time.sleep(100) |
|
36 raise |
|
37 |
|
38 if __name__ == "__main__": |
|
39 main() |