When I try who, I frequently see output such as this:

username  pts/0        2015-10-09 04:48 (mosh [2680])
username  pts/2        2015-10-12 00:04 ( via mosh [12364])
username  pts/6        2015-10-12 00:10 ( via mosh [9728])

Where my username is logged into several sessions. Unfortunately I do not know which one I am currently using. Is there a way to tell so that if I kill the mosh PID, I don't kill my own session?

1 Answer 1


The tty command will tell you which pseudo-terminal session you are running. And that can distinguish which line is yours.

  • In this case that returns /dev/pts/3 which is not even one if the listed ones. Does that make sense?
    – Startec
    Oct 12, 2015 at 2:17
  • I should clarify. I am using tmux, so it returns that value. However, exiting tmux returns /dev/pts/6. Do you know of a way to get the right shell identifier no matter what?
    – Startec
    Oct 12, 2015 at 2:18
  • 1
    I'm afraid of this question wandering around a bit. If you are running tmux, then do a ps $(pidof tmux) or ps -ef | grep [t]mux and that shows you the processes and tty that are running tmux.
    – rocky
    Oct 12, 2015 at 3:00
  • @Startec Yes, it makes sense that tmux reports a different pseudo terminal. The tmux process forks another process. That process in turn forks a shell for each window, and each shell has its own pseudo tty. pstree or, better, a dynamic process tree program called xps will show the process tree structure.
    – rocky
    Oct 12, 2015 at 12:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .