import os,json,time,datetime
from pathlib import Path
out=Path(__file__).parent
with (out/'process-observations.jsonl').open('a') as f:
 for _ in range(280):
  r={'at':datetime.datetime.now(datetime.timezone.utc).isoformat()}
  for side,ids in [('head',[87257,87633]),('base',[87844,88568])]:
   r[side]={str(pid):os.path.exists('/proc/'+str(pid)) for pid in ids}
  p=out/'project'/'background-result.txt'
  r['resultExists']=p.exists()
  if p.exists():r['result']=p.read_text().strip()
  f.write(json.dumps(r)+'\n'); f.flush()
  time.sleep(1)
