Exercise 3: Which Session and Window Is This Process In? — Possible Solution ============================================================================== Find it: $ pgrep -af "sleep 2000" 61008 sleep 2000 Proof 1 — its ancestors: $ pstree -s -p 61008 systemd(1)───SCREEN(61007)───sleep(61008) The SCREEN(61007) ancestor matches session 61007.jobs in screen -ls. (This shows the session, but not the window number.) Proof 2 — its environment: $ tr '\0' '\n' < /proc/61008/environ | grep -E '^(STY|WINDOW)=' STY=61007.jobs WINDOW=0 Screen set these variables when it started the program in window 0 of session 61007.jobs. WHY THIS WORKS AS AN ANSWER ------------------------------ It uses two independent sources — the process tree kept by the kernel and the environment screen gave the process — and notes which one gives the window number. As the chapter warns, the environment method only works for processes that were started inside screen.