There are many ways to obtain the PTS associated with a given process - such as using the
tty command or resolving
/proc/self/fd/0 (assuming it's open and not redirected) - but what about the inverse? How do I obtain the PID of the shell running the pts?
I can try to use something like
ps -t $(tty) but this does not provide enough information to reliably determine the root shell (i.e. multiple shell instances, PID reuse on long running systems, etc). The only way I can think of to this is to manually collect all processes associated with the terminal and visit each process's
/proc entry to determine process hierarchy and then assume it's the topmost parent process.
Is there a simple inverse
tty command I can use? One that gives me the PID without too much work?