Documented behavior: tmux sessions can be detached and attached again, according to the official tmux Getting Started guide. So if an SSH connection to a remote Mac drops, an ordinary foreground command is not guaranteed to continue. Run terminal work inside tmux and verify that you can reconnect before trusting it with a long research task. tmux does not protect against a host restart, a stopped service, or a crashed program.
This guide is for graduate students and researchers running scripts, builds, or command-line analysis on a remote Mac over SSH.
It also helps lab staff set up a safe recovery check before a job becomes important.
If the task depends on an interactive desktop, the GUI section explains why tmux alone is not enough.
Identify what actually disconnected
A lost SSH window, an ended terminal session, and an exited research process are different events. SSH provides a remote login connection; reconnecting opens a new connection and shell, not a restored copy of the old shell. Apple's Remote Login guidance covers enabling SSH access on a Mac. It does not promise that a command launched in a particular terminal will survive that terminal's loss.
Use the symptom, not the fact that SSH disconnected, to decide what to check:
| What you observe | What it suggests | First low-risk check |
|---|---|---|
| The SSH client closes, but the host responds again | The connection ended; the job's state is still unknown | Reconnect to the same host and account, then check tmux and logs |
| The named tmux session appears | The remote session is available to inspect | Attach to it and check whether the command is still active |
| No session appears, but a log exists | The session may have ended, or the command may have finished | Read the log and inspect output files before rerunning |
| The host cannot be reached | This is not enough evidence to determine job state | Check the host's availability and maintenance rules before acting |
A successful new login proves only that a new SSH connection works. It does not prove that the old process is running, finished correctly, or wrote complete results. The SSH manual describes SSH as a remote login and command execution client; it is not a task queue or result-recovery system.
Before any rerun, check whether the original command could still be active. Submitting it again without checking can create duplicate computation or overwrite output. If the state is unclear, preserve the log and output directory first.
Check whether the command was attached to the lost terminal
A command started directly at an SSH prompt is normally tied to the shell and terminal context in which it runs. When that connection disappears, the process may stop, may behave differently depending on the shell and program, or may have already finished. Treat its status as unknown until you find evidence. Do not assume either “it definitely stopped” or “it must still be running.”
| How the command was started | What it offers | What it does not establish |
|---|---|---|
| Ordinary foreground command | Direct interaction with the program in the current shell | Survival after a lost terminal or a way to reattach to its output |
nohup with output redirected |
A way to run a command with hangup handling and separate output | A resumable terminal session, host-failure recovery, or proof that results are complete |
| Command inside tmux | A remote terminal session that can be detached and reattached | Protection from a host restart, service termination, or program failure |
GNU documents nohup as a utility for running a command immune to hangups. That is not the same as reattaching to a terminal and inspecting the process interactively. On macOS, check the behavior of the actual installed command and shell rather than assuming every detail of GNU Coreutils applies.
Use a low-risk sequence to investigate:
- Reconnect with the same account and host name or address used for the original run.
- Check whether the expected tmux session exists, if the task was started there.
- Read the log from the expected working directory; look for a final completion message or an error.
- Check whether the process still exists using a command such as
pgrep -fl 'distinct-script-name'. Match a distinctive script or command string, and do not terminate a process just because its name looks familiar. - Inspect output files and compare them with the expected set of results. A file's existence alone does not prove the run completed successfully.
- If you cannot establish the task's state, copy or preserve its logs and outputs before deciding whether to rerun.
Keep the working directory and output path explicit. A new shell may start in a different directory, so checking the wrong folder can make a completed job look as if it produced nothing.
Keep terminal work in a named tmux session
tmux separates a terminal session from the SSH client used to view it. Its official guide describes detaching a session and attaching to it again; the tmux manual documents the commands and options. This lets you leave terminal work on the remote host while your local connection is unavailable. It does not make the host or program failure-proof.
First, check whether tmux is present and permitted on the Mac. If it is unavailable, ask the host administrator about the supported installation or use an approved alternative. Do not install software or change host policy on a shared research machine without permission.
A minimal workflow looks like this:
- Connect to the remote Mac using SSH and change to the project directory.
- Confirm that the input files and output location are correct. Create a run-specific directory so an earlier result is not silently overwritten.
- Start a named session with
tmux new -s analysis. - Inside the session, launch the command and redirect output to a log. For example:
python3 analysis.py > run.log 2>&1; status=$?; printf '%s\n' "$status" > run.exit. Replace the script and paths with the actual project values. - Detach from tmux with
Ctrl-bfollowed byd. This leaves the tmux session on the remote host; it does not stop the command. - Reconnect later and run
tmux list-sessions. If the named session exists, usetmux attach -t analysisto inspect it. Check the log, exit-status file, and output files before treating the run as successful.
For a long job, use a unique session and output path for each run. The exit-status file is useful only if the shell reached the printf command after the program ended; its absence does not prove that the program is still running. Review the log and process state together.
Decide whether tmux fits the task
Choose the recovery method based on what needs to stay alive and what evidence you need afterward.
- If the work is a terminal command that you need to inspect after reconnecting, use tmux. It keeps a named terminal session available for reattachment while the remote host and tmux remain running.
- If the command only needs to finish with redirected output and you do not need to reconnect to its terminal, consider an approved background method.
nohupmay be suitable for some command-line jobs, but verify the local implementation, output redirection, and exit-status handling first. - If the program needs a visible desktop, menus, dialogs, or ongoing mouse interaction, do not treat tmux as a GUI keep-alive tool. Use the application's recovery features and an appropriate remote desktop workflow.
- If the host may restart, enter maintenance, or reclaim resources, stop before relying on either method. Ask the administrator what happens to processes and files during those events.
- If results must be reproducible, require a log, a clear completion signal, and a check of the expected output files. A live terminal is not a substitute for evidence that the research result is valid.
This is the key decision: use tmux for terminal work that should remain inspectable after a client disconnect; use application-specific recovery for GUI work; and do not use either as a promise of host-level continuity.
Recover carefully when the session or result is missing
A missing tmux session has several possible explanations. The account or host may be different; the session may have ended; tmux may no longer be running; or the task may have completed or failed. The tmux FAQ is useful for understanding tmux behavior, but it cannot reveal what happened to a particular Mac or process.
| Evidence found | What to inspect next | Safer next action |
|---|---|---|
| No session under the expected name | Confirm the login account, host, and session list | Do not assume the process stopped; inspect logs and process state |
| Log ends with an error | Read the error context and check inputs or dependencies | Preserve the failed run before changing anything |
| Log ends without a clear completion message | Check the exit-status record and output files | Treat completion as unconfirmed until the outputs pass validation |
| Some output files are missing or incomplete | Compare against the expected outputs and any checkpoints | Save the current evidence; rerun only after assessing overwrite and duplication risks |
| Host is unavailable or was restarted | Ask the operator about maintenance and process policy | Do not infer process survival from a later successful login |
Avoid force-quitting processes or cleaning the output directory while the cause is unknown. If the work is expensive or scientifically important, make a copy of the existing log and result folder before recovery. For future runs, use an explicit checkpoint or restart mechanism in the analysis software where available.
macOS has service-management mechanisms, documented in Apple's Service Management reference. That does not make a user-launched tmux session a managed recovery service. A lab should use only an administrator-approved service design and should separately define how data is preserved.
Handle GUI work and host failures separately
tmux manages terminal sessions. It does not keep a scientific desktop application interactive after the SSH client disconnects, and it does not automatically save a GUI application's state. If a task depends on dialogs, desktop rendering, or repeated user input, use the application's autosave, checkpoint, or project-recovery feature and test how that feature behaves in the actual remote desktop setup.
Also confirm the remote Mac's operating and maintenance rules with whoever manages it. A restart, planned maintenance, resource policy, terminated tmux server, or program crash can end the work. Even if the log survives, unsaved program state may not. Keep important inputs and outputs in a location with an understood backup and retention policy; do not assume tmux provides one.
Answer common recovery questions
Will an ordinary script continue after SSH disconnects?
There is no safe general guarantee for an ordinary foreground command. Its outcome depends on how it was launched and what happens to its terminal and process. If the result matters, start it inside tmux, confirm you can detach and reattach, and keep separate logs. After a real disconnect, inspect the process and output rather than deciding from the connection event alone.
How does tmux keep a research task available?
Start a named session on the remote Mac, launch the command inside it, and detach without ending the session. After reconnecting, list sessions and attach to the one holding the command. Use a log and exit-status record as separate evidence. Test the workflow with a harmless command first, because tmux's session behavior does not cover host restarts or program crashes.
How can you find the old terminal after reconnecting?
Log in to the same host and account, then use tmux list-sessions. If the expected session appears, attach with tmux attach -t analysis. If it does not, check the process list, log, exit status, and output directory. A newly opened SSH shell is not the old terminal, and repeating the command before checking can create duplicate work.
Does tmux protect GUI applications or recover from a Mac restart?
No. tmux allows you to detach from and reattach to a terminal session while the relevant remote components remain available. It does not restore a host after reboot, preserve a crashed program, or provide GUI autosave. Use the research application's own recovery features and ask the host operator how maintenance, process cleanup, and data retention are handled.
Validate before trusting a long run
Do not test recovery for the first time with an irreplaceable experiment. Use a harmless command that writes observable progress and a final output file. Start it in a named tmux session, detach, close the SSH client, reconnect, and check the session, process, log, exit status, and output. Then verify that the result is complete, not merely present.
A lab can use this release checklist before allowing a long terminal task to run unattended:
- [ ] The task runs inside the intended named tmux session.
- [ ] The operator can detach and reconnect to that same session.
- [ ] Logs are written to the expected project location.
- [ ] Completion or failure can be distinguished from an incomplete run.
- [ ] Output files can be checked without rerunning the analysis.
- [ ] The host's restart, maintenance, and data-retention rules are known.
- [ ] A GUI task has a separate application-level save or recovery plan.
If any essential item fails, do not mark the environment as ready for unattended research work. Fix the workflow or choose a task that can safely be resumed.
For research that must run on macOS, a lab's existing Linux or Windows machines may lack the required macOS environment, while buying a dedicated Mac ties up more budget and makes access depend on that device's availability. A generic shell session alone also leaves uncertainty about recovery and output validation. When the need is temporary and the task is terminal-based, renting a remote Mac from RUVCLOUD can provide a macOS host without purchasing a lab machine; test it with a representative script and verify result export before choosing a usage period. Compare the RUVCLOUD plans and remote Mac options, and use the RUVCLOUD English service overview to check whether the access model fits the lab. If the work requires uninterrupted physical peripherals or sustained host-level availability beyond the published operating rules, a dedicated lab Mac or administrator-managed system may be the better choice.