5

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 (75.139.11.119 via mosh [12364])
username  pts/6        2015-10-12 00:10 (75.139.11.119 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?

Startec
  • 1,839
  • 4
  • 24
  • 27

1 Answers1

6

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

rocky
  • 1,978
  • 11
  • 23
  • In this case that returns `/dev/pts/3 ` which is not even one if the listed ones. Does that make sense? – Startec Oct 12 '15 at 02: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 '15 at 02: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 '15 at 03: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](http://motif-pstree.sourceforge.net/) will show the process tree structure. – rocky Oct 12 '15 at 12:22