106

I had to reboot my box today. I had several program running in tmux sessions. They seem to be still alive, how can I reattach to them? I tried tmux a processID but it didn't work.

/home/me 21$ ps aux | grep tmux
me    1299  0.0  0.0  22244  1920 ?        Ss   Apr28   0:40 tmux -2 -f /tmp/r-plugin-me/tmux.conf new-session -s vimrpluginme1398670569alnn51oynp1vollnn51f2v4r_ied_delta1meRalphaCalibr VIMINSTANCEID=alnn51oynp1vollnn51f2v4r_ied_delta1meRal
me    2575  0.0  0.0  54164  3500 ?        S    07:35   0:00 xterm -e tmux -2 -f /home/me/.tmux.conf -S /tmp/vX0qRrR/78
me    2577  0.0  0.0  19892  1400 pts/2    Ss+  07:35   0:00 tmux -2 -f /home/me/.tmux.conf -S /tmp/vX0qRrR/78
me    2579  0.0  0.0  22128  1832 ?        Ss   07:35   0:00 tmux -2 -f /home/me/.tmux.conf -S /tmp/vX0qRrR/78
me    5155  0.0  0.0   6380   756 pts/4    S+   07:46   0:00 grep tmux
me   31340  0.0  0.0  23348  3000 ?        Ss   Apr28   0:17 tmux -2 -f /home/me/.tmux.conf -S /tmp/vIqEM06/78
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
statquant
  • 13,672
  • 21
  • 91
  • 162
  • 1
    I assume you mean the `tmux` sessions are running on another machine, because I don't see how they would survive a reboot by the machine they are running on. – chepner May 02 '14 at 19:10

2 Answers2

152

You can not re-attach a process id. You need to reattach the corresponding tmux session.

So do tmux ls. Pick whatever session you want to re-attach. Then do tmux attach -d -t <session id> to re-attach it to a new tmux instance and release it from the old one.

oakad
  • 6,945
  • 1
  • 22
  • 31
  • 41
    it's also hand to just use `tmux attach` if you only have one session you've detached from. – jondavidjohn Dec 16 '19 at 16:35
  • 5
    `tmux a -t ` also seemed to work for me. – akki Oct 01 '21 at 13:33
  • 1
    `tmux attach -d -t` also worked for me when I detached from a session using `Ctrl + b +d` but `tmux ls` was still showing that session as attached. – user_3pij Jun 22 '22 at 17:44
  • `-d` means "Detach others on the session (Maximize window by detach other clients)" [reference](https://tmuxcheatsheet.com). If there is only one session, `tmux attach -d -t session_name` is [fine](https://superuser.com/questions/610608/detach-the-other-tmux-clients). – tinystone Sep 16 '22 at 05:52
  • 1
    `tmux -d` is used to Detach others who are in the session - [details](https://www.debugpointer.com/linux/how-to-disconnect-all-other-tmux-users). – Lokesh Sinha Sep 26 '22 at 23:50
35

If you only have one session detached you can just do

tmux attach

also if you're going to be working in multiple sessions it might be a good idea to name your sessions

tmux new -s ssh-to-staging
Ctrl b, d   # Detach from session
tmux new -s ssh-to-s3
Ctrl b, d   Detach from session

now when you do tmux ls you can reattach more easily without guessing.

tmux attach -d -t ssh-to-s3

You also might wanna bookmark this cheat sheet

lacostenycoder
  • 10,623
  • 4
  • 31
  • 48