I'm trying to determine whether a command I'm running is within an SSH session. Usually this works fine by checking for
$SSH_CONNECTION or walking the process tree and looking for
However, if I start a
screen session locally and then re-attach it through SSH, neither of those works.
Is there some way from within the reattached screen session to determine which shell the session is currently attached to?
The process tree just looks like
shell(X) --> screen(Y) --> systemd(1), which makes sense, since the screen session probably gets reparented when I exit the local terminal.
screen -ls does not say anything more than
(Attached), with only the PID
Y, no helpful PID of where it is currently attached.
The process tree of
shell(A) where it is attached includes a single child
screen(B), but I cannot find a way to link the PIDs
B. I even tried to find the other end of the unix socket being used by screen but it comes up empty. (even checked as
Is this just something that isn't possible?