import subprocess, os, glob, time, struct def mem_open(pid): return os.open(f'/proc/{pid}/mem', os.O_RDONLY) def find_hosts(): hosts=[] for p in glob.glob('/proc/[0-9]*'): pid=int(os.path.basename(p)) try: cmd=open(f'/proc/{pid}/cmdline','rb').read().replace(b'\0',b' ').decode('utf8','replace') maps=open(f'/proc/{pid}/maps').read() except Exception: continue if 'soothe2' in maps and 'reaper' not in cmd: hosts.append(pid) return hosts os.system("pkill -9 -x reaper 2>/dev/null; pkill -9 -f '[y]abridge' 2>/dev/null; sleep 1") proc=subprocess.Popen(['/usr/bin/reaper','-nosplash','-ignoreerrors','-renderproject','/home/m/soothe-bt/render_long.rpp'], stdout=open('/dev/null','w'),stderr=subprocess.STDOUT) t0=time.time(); host=None while time.time()-t0<60 and not host: hs=find_hosts(); host=hs[0] if hs else None; time.sleep(0.2) print('host',host, flush=True) fd=mem_open(host) def snap(tag): out=open('/tmp/snap_%s.bin'%tag,'wb'); idx=open('/tmp/snap_%s.idx'%tag,'wb') t0=time.time(); nreg=0; nb=0 for line in open(f'/proc/{host}/maps').read().splitlines(): p=line.split(); lo,hi=(int(x,16) for x in p[0].split('-')) if 'r' not in p[1]: continue a=lo while a