Close the terminal, the job stays

Close the terminal and the job inside tmux keeps running.

Close the outside terminal and the job inside tmux keeps running. The session sits on the server process, not in the window you just closed. To put detach and attach on one page for a colleague, open a room on oakmeet.

The result to search for is close the terminal and the job stays. tmux(1) says a session survives an accidental disconnect, such as an ssh timeout, or an intentional C-b d. Come back with tmux attach.

tmux new -s jobC-b dtmux attach
C-b dDefault detach keys
offdestroy-unattached default
tmux attachReattach command in the manual

You detach the client, not the job

The outside terminal can close

Getting Started: detach from the outside terminal, then attach later from the same or another one. The walkthrough is close the xterm, go elsewhere, attach, and the compile is still on that server.

exit inside closes the window

The manual: when the shell command completes, the window closes. exit in the last pane is not detach. With no sessions left, exit-empty defaults to on and the server exits.

ActionCommand or keysDoes the job stay
Named sessiontmux new -s jobAttached to this terminal
Detach on purposeC-b then dSession and programs continue
Close the terminalThe client is goneThe session stays by default
Come backtmux attach -t jobSame session

Four steps, then the window can close

  1. 01
    Open a session named job

    Install tmux from your platform packages. Getting Started does not name one installer. After that, man 1 tmux is this manual. Then tmux new -s job. The wiki writes the same flag as tmux new -smysession. With no -s, the first session is 0.

  2. 02
    Start the long command inside

    A new session has one window, one pane, and a shell. The status line sits at the bottom; the session name is on the left. Start the program you want left running. You are still attached to this terminal.

  3. 03
    C-b d, then close the terminal

    The default prefix is C-b. Press Ctrl-b, release, then d. That is not Ctrl-d. The documented line is [detached (from session mysession)], with your session name. Then close the terminal.

  4. 04
    Attach from a new terminal

    tmux ls lists sessions on the server. Then tmux attach -t job. tmux attach with no -t takes the most recently used session that has no client. The key list is C-b ?.

tmux new -s job
# start the long command, then press C-b d
tmux ls
tmux attach -t job

You closed the outside terminal. exit inside the pane is what closes the window.

Why the session survives the close
destroy-unattached defaults to off: after the last client detaches, the session is left in place. Set it to on and detach destroys the session.
Name already taken
Session names must be unique. If job exists, tmux new -A -s job attaches, or creates it. The wiki writes tmux new -Asmysession.
Prefix was changed
prefix can be another key. Then C-b d is not detach. C-b ? lists bindings while the default prefix is still in force.

Put the four steps on one page

If two people need to agree which key counts as detach, draw new, C-b d, and attach on one board. oakmeet is a browser whiteboard: a space code, no account. It does not run tmux and it does not keep your process alive.

Align, then go back to the terminal. Next: start a room, or see create and join a space and features.

How is closing the terminal different from exit?

Closing the outside terminal, or an ssh timeout, leaves the session. exit in the pane ends the command and closes the window. With no sessions, the server exits.

Which session does tmux attach pick?

With no -t, it attaches the most recently used session that has no client. Name one with tmux attach -t job. tmux ls shows the names.

C-b d did not detach?

C-b is only the default prefix, and Ctrl must be released before d. If prefix changed, that pair is no longer detach-client. The binding list is prefix, then question mark.

Does oakmeet keep this job running?

No. oakmeet is a short-lived browser room and a board. The start link is only so you can lay out detach and attach. The job stays on that machine's tmux server.

Start a room