I start two new tmux sessions, the session name is variably build from a timestamp. (the commands create a new, detached tmux session, which first changes the directory, lists the content and then opens bash, in order to keep the session open)

 tmux new -d -s tmux-s1-2014-12-04-16-12-12-103728 'cd /home/user/dir/ect/; ls; bash'
 tmux new -d -s tmux-s2-2014-12-04-16-12-12-103728 'cd /home/user/dir/ory/; ls; bash'

Now if i us htop or ps aux to see if they are still running, I always just find one of them. (e.g. ps aux | grep tmux)

user     13556  0.0  0.0  26288  1716 ?        Ss   16:12   0:00 tmux new -d -s tmux-s1-2014-12-04-16-12-12-103728 cd /home/user/dir/ect/; ls; bash
user     13686  0.0  0.0   8072   864 pts/1    S+   16:14   0:00 grep tmux

Yet when i use tmux list-sessions both are listed:

tmux-s1-2014-12-04-16-12-12-103728: 1 windows (created Thu Dec  4 16:12:20 2014) [80x23]
tmux-s2-2014-12-04-16-12-12-103728: 1 windows (created Thu Dec  4 16:12:20 2014) [80x23]


I've now tested a little further and from what I understand now, detached sessions are invisible to htop/ps.. because of reasons. The first established session will be visible, even if detached.

I've created three sessions, all with bash and detached the first and second session. The third session is still attached. Here's the output of htop when filtering for tmux.

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
17382 user       20   0 26296  1808  1176 S  5.0  0.1  0:00.86 ├─ tmux new -s first_session
17641 user       20   0 17552  1164   908 S  0.0  0.0  0:00.00 │  │  └─ tmux attach -t third_session

Whereas tmux list-sessions will still show all three:

first_session: 1 windows (created Fri Dec  5 10:35:11 2014) [80x23]
second_session: 1 windows (created Fri Dec  5 10:35:23 2014) [80x23]
third_session: 1 windows (created Fri Dec  5 10:35:37 2014) [80x23] (attached)

The question is still the same.. Why is htop or ps aux unable to list all detached and attached sessions?


Tmux by default will only run one server process per user, and this server process can have multiple sessions. A Tmux client and the server communicate via a Unix domain socket in the /tmp directory. The -L option can be used to specify a different socket; a new server is created for each socket.

Source: http://hyperpolyglot.org/multiplexers

The tmux sessions aren't displayed by ps or htop because they are not processes. As you've discovered, the single tmux server process hosting all of the sessions for your user does show up, along with any tmux client processes that may be attached to your session(s). What you will see in the process list are any shells and other child processes that you have invoked in panes and windows of your tmux sessions.

Check out this partial output of pstree -ap from a Linux machine where I am running tmux:

  |   |-sshd,18196
  |       `-sshd,18201
  |           `-bash,18202
  |               `-tmux,18297 att
  |-tmux,10496 new-session -s main
  |   |-bash,10497
  |   |   `-ssh,10584 otherhost.mydomain.local
  |   |-bash,17650
  |   `-bash,18303
  |       |-less,18390
  |       `-pstree,18389 -ap
  |   `-bash,18487
  |       `-cat,18573 - this-is-in-another-session

You can see my tmux server process (10496). The first session I created has 3 panes (all running bash). One is ssh'd to otherhost. Another is sitting at a prompt, and so has no children. And the third is displaying pstree output in less. You can also see my tmux client process (18297).

Those 3 panes are in one session that is attached.

I have another session with one pane running bash and the cat process you see. That is detached, but still a child of the single tmux server process.

  • I reckoned that only one server process is used, but why are detached sessions not recognized by ps or htop? As they might be running a script or anything else and should be displayed. thank you – Daedalus Mythos Dec 5 '14 at 10:26
  • 1
    I've added some further details explaining what you actually see in ps output. – cpugeniusmv Dec 5 '14 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.