OK I'm new to this. I installed tmux to run a several days experiment. After typing tmux new -s name I got a new window with green banner at the bottom. I compile and run java program. Now I do not know how to exit the window (while leave it running). The bash (or whatever) cursor is not responding because the java program is still running. My solution so far is to quit the Terminal program completely and reopen it again. Any ideas on how to quit the tmux window without exiting the whole Terminal program?
2 Answers
Detach from currently attached session
Session
Ctrl+ b d or Ctrl+ b :detach
Screen
Ctrl+ a Ctrl+ d or Ctrl+ a :detach
-
7You then need to run
tmux attachto enter the open session again after re-connecting.Besi– Besi2019-02-27 17:56:55 +00:00Commented Feb 27, 2019 at 17:56 -
1I've always done
ENTER ~ .This seems nicer.Thomas Eding– Thomas Eding2019-06-24 16:54:29 +00:00Commented Jun 24, 2019 at 16:54 -
Is there space between
~and.and it also returnspermission denied: /home/folder@ThomasEdingalper– alper2020-10-18 19:23:05 +00:00Commented Oct 18, 2020 at 19:23 -
@alper No spaces at all in the expression I typed above.Thomas Eding– Thomas Eding2020-10-22 21:21:42 +00:00Commented Oct 22, 2020 at 21:21
The previous answers are incomplete, I believe. What :detach does is to shut down the viewports that are displaying tmux activity. However, tmux itself is still running in the background as you can see by running ps:
myuser 1799 0.0 0.0 2500052 4632 ?? Ss 21Feb16 0:48.39 tmux new-session -s Dev
In fact, even if you quit terminal and start it up again, any tmux processes are STILL running in the background.
To actually kill the tmux process itself, you have to do:
tmux kill-session [-t session_name]
or simply:
kill -9 1799
-
7Imho, it would make more sense to comment about some answer's deficiencies under that particular answer and leave your post as a complete and contained answer without requiring readers to find out which answers are previous and then analyse them.techraf– techraf2016-03-02 14:59:05 +00:00Commented Mar 2, 2016 at 14:59
-
6I think OP specifically wanted the background process (java, in his case) to continue running, so killing it would be counter-productive. More interesting would be to re-attach later to the detached process with
tmux attach-session.ThomasH– ThomasH2018-03-27 15:46:58 +00:00Commented Mar 27, 2018 at 15:46 -
4Using
kill -9is absolutely the Wrong Way(tm) to do this. This sends aSIGKILLsignal which will not allow the process to clean up after itself, which can cause serious problems with dangling resources.SIGKILLshould only be used when a process has already politely been asked to cleanup and shut down viaSIGTERMor similar and, for whatever reason, refuses to do so; even then, one should still avoid sendingSIGKILLif they can. This answer infers (incorrectly) that it should be one of the first things a person should do to shutdown a background process like a tmux server.eestrada– eestrada2019-08-12 23:47:00 +00:00Commented Aug 12, 2019 at 23:47
man tmux | less -p detachCtrl+b swhich will list sessions, navigate to the one you want to kill and type:kill-session.exitand it worked on my Mac terminal.exitdon't work for me.