<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.anunna.wur.nl/index.php?action=history&amp;feed=atom&amp;title=Tutorials%2FSlurm-Persistent-Shell</id>
	<title>Tutorials/Slurm-Persistent-Shell - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.anunna.wur.nl/index.php?action=history&amp;feed=atom&amp;title=Tutorials%2FSlurm-Persistent-Shell"/>
	<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Tutorials/Slurm-Persistent-Shell&amp;action=history"/>
	<updated>2026-11-24T05:32:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.anunna.wur.nl/index.php?title=Tutorials/Slurm-Persistent-Shell&amp;diff=3283&amp;oldid=prev</id>
		<title>Honfi001: Honfi001 moved page Tutorials/slurm-persistent-shell to Tutorials/Slurm-Persistent-Shell without leaving a redirect</title>
		<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Tutorials/Slurm-Persistent-Shell&amp;diff=3283&amp;oldid=prev"/>
		<updated>2026-11-23T10:28:07Z</updated>

		<summary type="html">&lt;p&gt;Honfi001 moved page &lt;a href=&quot;/index.php?title=Tutorials/slurm-persistent-shell&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Tutorials/slurm-persistent-shell (page does not exist)&quot;&gt;Tutorials/slurm-persistent-shell&lt;/a&gt; to &lt;a href=&quot;/Tutorials/Slurm-Persistent-Shell&quot; title=&quot;Tutorials/Slurm-Persistent-Shell&quot;&gt;Tutorials/Slurm-Persistent-Shell&lt;/a&gt; without leaving a redirect&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:28, 23 November 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Honfi001</name></author>
	</entry>
	<entry>
		<id>https://wiki.anunna.wur.nl/index.php?title=Tutorials/Slurm-Persistent-Shell&amp;diff=3282&amp;oldid=prev</id>
		<title>Honfi001: Created page with &quot;= Persistent Shell on a Compute Node =  &#039;&#039;A follow-up to the &#039;&#039;&#039;Interactive Slurm&#039;&#039;&#039; series for the HPC Advanced course. It builds on Part 3: salloc — allocations and steps.&#039;&#039;  You start something on a compute node, you need to go home, and you want to find it exactly as you left it tomorrow morning: same shell, same history, the program still running. On your own computer you would use &lt;code&gt;tmux&lt;/code&gt;: start a session, detach,...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.anunna.wur.nl/index.php?title=Tutorials/Slurm-Persistent-Shell&amp;diff=3282&amp;oldid=prev"/>
		<updated>2026-11-23T10:26:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Persistent Shell on a Compute Node =  &amp;#039;&amp;#039;A follow-up to the &amp;#039;&amp;#039;&amp;#039;Interactive Slurm&amp;#039;&amp;#039;&amp;#039; series for the HPC Advanced course. It builds on &lt;a href=&quot;/Tutorials/Slurm-Interactive-Salloc&quot; title=&quot;Tutorials/Slurm-Interactive-Salloc&quot;&gt;Part 3: salloc — allocations and steps&lt;/a&gt;.&amp;#039;&amp;#039;  You start something on a compute node, you need to go home, and you want to find it exactly as you left it tomorrow morning: same shell, same history, the program still running. On your own computer you would use &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt;: start a session, detach,...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Persistent Shell on a Compute Node =&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;A follow-up to the &amp;#039;&amp;#039;&amp;#039;Interactive Slurm&amp;#039;&amp;#039;&amp;#039; series for the HPC Advanced course. It builds on [[Tutorials/Slurm-Interactive-Salloc|Part 3: salloc — allocations and steps]].&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
You start something on a compute node, you need to go home, and you want to find it exactly as you left it tomorrow morning: same shell, same history, the program still running. On your own computer you would use &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt;: start a session, detach, come back later and attach again.&lt;br /&gt;
&lt;br /&gt;
On the cluster that needs one more idea, because &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; has to run in the right place. This page shows where that is, and how to set it up so that your session survives a lost connection and a login node reboot, and is still cleaned up properly when you are done.&lt;br /&gt;
&lt;br /&gt;
By the end of this page you will be able to:&lt;br /&gt;
&lt;br /&gt;
* explain why &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; on the login node, or inside an &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; session, does not give you a persistent shell on a compute node;&lt;br /&gt;
* start a &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; session on a compute node from a batch job;&lt;br /&gt;
* attach to it, detach, lose your connection, and attach again;&lt;br /&gt;
* end it so that your resources are released straight away.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;You need:&amp;#039;&amp;#039;&amp;#039; [[Tutorials/Slurm-Interactive-Salloc|Interactive Slurm, Part 3]], and basic &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt;: start a session, detach with &amp;lt;code&amp;gt;Ctrl-b d&amp;lt;/code&amp;gt;, attach again.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Time:&amp;#039;&amp;#039;&amp;#039; about 30 minutes.&lt;br /&gt;
&lt;br /&gt;
== Why the obvious ways do not work ==&lt;br /&gt;
&lt;br /&gt;
There are three obvious places to put &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt;, and each one breaks in a different way:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Where tmux runs !! What goes wrong&lt;br /&gt;
|-&lt;br /&gt;
| on the &amp;#039;&amp;#039;&amp;#039;login node&amp;#039;&amp;#039;&amp;#039; || The login node is not a compute node, so your work does not belong there. And login nodes are rebooted now and then for maintenance, which ends every &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; session on them.&lt;br /&gt;
|-&lt;br /&gt;
| inside an &amp;#039;&amp;#039;&amp;#039;interactive shell&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;srun --pty bash&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;sinteractive&amp;lt;/code&amp;gt;) || That shell is a job &amp;#039;&amp;#039;&amp;#039;step&amp;#039;&amp;#039;&amp;#039;. When it ends, Slurm ends everything started inside it, &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; included. [[Tutorials/Slurm-Interactive-Salloc|Part 3]] shows this happening.&lt;br /&gt;
|-&lt;br /&gt;
| on the login node, running &amp;lt;code&amp;gt;srun --pty bash&amp;lt;/code&amp;gt; inside it || Survives your laptop disconnecting, but the &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; that holds the step open lives on the login node, so a login node reboot ends the step, and everything in it.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
They all fail for one reason. Here it is, the most useful sentence on this page:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A job step lives only as long as the program that launched it.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Every &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; you type is launched from the login node, so every step it creates is tied to something on the login node: your connection, your terminal, or the login node itself. To get a session that outlives all of those, it has to be launched by something that is &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039; on the login node.&lt;br /&gt;
&lt;br /&gt;
== The idea: let Slurm start tmux for you ==&lt;br /&gt;
&lt;br /&gt;
When you submit a batch job with &amp;lt;code&amp;gt;sbatch&amp;lt;/code&amp;gt;, Slurm starts your script &amp;#039;&amp;#039;&amp;#039;on the compute node itself&amp;#039;&amp;#039;&amp;#039;, as a step called &amp;lt;code&amp;gt;batch&amp;lt;/code&amp;gt;. Nothing of yours stays behind on the login node, so there is nothing there to lose.&lt;br /&gt;
&lt;br /&gt;
So the recipe is:&lt;br /&gt;
&lt;br /&gt;
# a small batch job whose only work is to start a &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; session on the compute node and keep the job alive while that session exists;&lt;br /&gt;
# a throwaway &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; step each time you want to look at it, to attach.&lt;br /&gt;
&lt;br /&gt;
The attaching step can die whenever it likes, because the session does not live in it.&lt;br /&gt;
&lt;br /&gt;
== Step 1: The batch script ==&lt;br /&gt;
&lt;br /&gt;
Save this as &amp;lt;code&amp;gt;tmux-work.sh&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH --job-name=tmux-work&lt;br /&gt;
#SBATCH --time=00:10:00&lt;br /&gt;
#SBATCH --cpus-per-task=1&lt;br /&gt;
tmux new-session -d -s work&lt;br /&gt;
while tmux has-session -t work 2&amp;gt;/dev/null; do sleep 30; done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Line by line:&lt;br /&gt;
&lt;br /&gt;
* the &amp;lt;code&amp;gt;#SBATCH&amp;lt;/code&amp;gt; lines are the same options you give &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt;, written into the script: a name, a time limit, and the cores;&lt;br /&gt;
* &amp;lt;code&amp;gt;tmux new-session -d -s work&amp;lt;/code&amp;gt; starts a &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; session called &amp;lt;code&amp;gt;work&amp;lt;/code&amp;gt;, &amp;#039;&amp;#039;&amp;#039;detached&amp;#039;&amp;#039;&amp;#039; (&amp;lt;code&amp;gt;-d&amp;lt;/code&amp;gt;), so it runs without a screen attached;&lt;br /&gt;
* the &amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt; loop checks every 30 seconds whether the session still exists. As long as it does, the script keeps running, and so does your job. When you close the session, the loop ends, the script ends, and &amp;#039;&amp;#039;&amp;#039;the job ends by itself&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
This is the exact script used for every example on this page. For real work, ask for what you need: in particular, &amp;#039;&amp;#039;&amp;#039;add &amp;lt;code&amp;gt;#SBATCH --mem=4G&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; (or however much you need), because without it you get the default of 100 MB, and set &amp;lt;code&amp;gt;--time&amp;lt;/code&amp;gt; to how long you will really use it.&lt;br /&gt;
&lt;br /&gt;
Submit it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sbatch tmux-work.sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Submitted batch job 44379814&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then wait until it is running, and note the job ID:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
squeue -j 44379814&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
             JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)&lt;br /&gt;
          44379814      main tmux-wor honfi001  R       0:05      1 node250&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; means running, on &amp;lt;code&amp;gt;node250&amp;lt;/code&amp;gt;. Your session is now waiting for you there.&lt;br /&gt;
&lt;br /&gt;
== Step 2: Look in, then attach ==&lt;br /&gt;
&lt;br /&gt;
Before attaching, we looked at the session from outside, with a short &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; step. It does four things: lists the &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; sessions, asks Linux which part of Slurm the &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; server belongs to (its &amp;lt;code&amp;gt;cgroup&amp;lt;/code&amp;gt;), asks the same about itself, and types a clock into the session so that we have something to watch later:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
srun --jobid=44379814 --overlap bash -c &amp;#039;&lt;br /&gt;
  date -Is; tmux ls&lt;br /&gt;
  P=$(tmux display -p -t work &amp;quot;#{pid}&amp;quot;); echo server pid $P; cat /proc/$P/cgroup&lt;br /&gt;
  echo this step:; cat /proc/self/cgroup&lt;br /&gt;
  tmux send-keys -t work &amp;quot;while true; do date +%T; sleep 5; done&amp;quot; Enter&amp;#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
2026-11-23T10:01:56+01:00&lt;br /&gt;
work: 1 windows (created Mon Nov 23 10:01:43 2026)&lt;br /&gt;
server pid 1532493&lt;br /&gt;
0::/system.slice/slurmstepd.scope/job_44379814/step_batch/user/task_0&lt;br /&gt;
this step:&lt;br /&gt;
0::/system.slice/slurmstepd.scope/job_44379814/step_0/user/task_0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Keep the two &amp;lt;code&amp;gt;0::&amp;lt;/code&amp;gt; lines in mind: they explain everything in Step 3. You do not need any of this for normal use. Normally you just attach:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
srun --jobid=44379814 --overlap --pty tmux attach -t work&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a new step in your job, as in Part 3: &amp;lt;code&amp;gt;--jobid&amp;lt;/code&amp;gt; puts it in the job you already have, &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt; lets it share the job&amp;#039;s cores with any other step that is running, such as an attach you still have open in another terminal, and &amp;lt;code&amp;gt;--pty&amp;lt;/code&amp;gt; connects your keyboard and screen. The program it runs is &amp;lt;code&amp;gt;tmux attach&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You are now in the &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; session on &amp;lt;code&amp;gt;node250&amp;lt;/code&amp;gt;, with the &amp;lt;code&amp;gt;[work]&amp;lt;/code&amp;gt; status bar at the bottom and the clock ticking every five seconds. Work as you normally would.&lt;br /&gt;
&lt;br /&gt;
== Step 3: Leave, the hard way ==&lt;br /&gt;
&lt;br /&gt;
The polite way to leave is to detach with &amp;lt;code&amp;gt;Ctrl-b d&amp;lt;/code&amp;gt;. We tested the rude way: while attached, we &amp;#039;&amp;#039;&amp;#039;killed the connection&amp;#039;&amp;#039;&amp;#039; from outside, as if the network had dropped or the laptop lid had closed. The clock had printed up to &amp;lt;code&amp;gt;10:02:31&amp;lt;/code&amp;gt; when the connection went at 10:02:33.&lt;br /&gt;
&lt;br /&gt;
Then, from a fresh login, we looked at the session from another step:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
srun --jobid=44379814 --overlap bash -c &amp;quot;tmux ls; tmux capture-pane -p -t work | grep -v &amp;#039;^$&amp;#039; | tail -4&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
work: 1 windows (created Mon Nov 23 10:01:43 2026)&lt;br /&gt;
10:02:26&lt;br /&gt;
10:02:31&lt;br /&gt;
10:02:36&lt;br /&gt;
10:02:41&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The session is still there, and the clock &amp;#039;&amp;#039;&amp;#039;kept ticking&amp;#039;&amp;#039;&amp;#039; after the connection was gone: &amp;lt;code&amp;gt;10:02:36&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;10:02:41&amp;lt;/code&amp;gt; were printed with nobody attached. (&amp;lt;code&amp;gt;tmux capture-pane -p&amp;lt;/code&amp;gt; prints what is on the session&amp;#039;s screen. Normally you would simply attach again and look.)&lt;br /&gt;
&lt;br /&gt;
=== Why it survived ===&lt;br /&gt;
&lt;br /&gt;
Go back to the two &amp;lt;code&amp;gt;0::&amp;lt;/code&amp;gt; lines from Step 2. The first is the &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; server: &amp;#039;&amp;#039;&amp;#039;job 44379814, step &amp;lt;code&amp;gt;batch&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;. It lives in the batch step, which Slurm started on the compute node, and which ends only when your script ends. The second line is the step we asked from, a throwaway &amp;lt;code&amp;gt;srun&amp;lt;/code&amp;gt; step, like every attach. When an attaching step dies, only that step ends.&lt;br /&gt;
&lt;br /&gt;
Being inside the job also means that everything you run in the session uses the cores your job was given, and that it &amp;#039;&amp;#039;&amp;#039;cannot outlive the job&amp;#039;&amp;#039;&amp;#039;: when the job ends, for any reason, Slurm ends everything in it.&lt;br /&gt;
&lt;br /&gt;
== Step 4: Finish, and give the resources back ==&lt;br /&gt;
&lt;br /&gt;
When you are done, close the session: type &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt; in every window, or run &amp;lt;code&amp;gt;tmux kill-session -t work&amp;lt;/code&amp;gt;. We did it from outside:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
srun --jobid=44379814 --overlap tmux kill-session -t work&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Within 30 seconds the loop in the script notices, the script ends, and the job ends with it. There is nothing to cancel. Here is the whole job afterwards:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sacct -j 44379814 -o JobID%15,JobName%10,End,Elapsed,State,ExitCode&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
          JobID    JobName                 End    Elapsed      State ExitCode&lt;br /&gt;
--------------- ---------- ------------------- ---------- ---------- --------&lt;br /&gt;
       44379814  tmux-work 2026-11-23T10:03:13   00:01:30  COMPLETED      0:0&lt;br /&gt;
 44379814.batch      batch 2026-11-23T10:03:13   00:01:30  COMPLETED      0:0&lt;br /&gt;
44379814.extern     extern 2026-11-23T10:03:13   00:01:30  COMPLETED      0:0&lt;br /&gt;
     44379814.0       bash 2026-11-23T10:01:56   00:00:04  COMPLETED      0:0&lt;br /&gt;
     44379814.1       tmux 2026-11-23T10:02:05   00:00:03     FAILED      1:0&lt;br /&gt;
     44379814.2       tmux 2026-11-23T10:02:33   00:00:19 CANCELLED+      0:9&lt;br /&gt;
     44379814.3       bash 2026-11-23T10:02:44   00:00:04  COMPLETED      0:0&lt;br /&gt;
     44379814.4       tmux 2026-11-23T10:02:55   00:00:04  COMPLETED      0:0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Everything from this page is in there:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;batch&amp;lt;/code&amp;gt; is your script, holding the &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; session. It ran for the whole job and ended &amp;lt;code&amp;gt;COMPLETED&amp;lt;/code&amp;gt; when the session closed;&lt;br /&gt;
* &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.3&amp;lt;/code&amp;gt; are the two times we looked in from outside: the check in Step 2, and the &amp;lt;code&amp;gt;capture-pane&amp;lt;/code&amp;gt; in Step 3;&lt;br /&gt;
* &amp;lt;code&amp;gt;.1&amp;lt;/code&amp;gt; is a failed attach: our test terminal had no terminal type set (see [[#Troubleshooting|Troubleshooting]]);&lt;br /&gt;
* &amp;lt;code&amp;gt;.2&amp;lt;/code&amp;gt; is the attach whose connection we killed: &amp;lt;code&amp;gt;CANCELLED&amp;lt;/code&amp;gt;, by signal 9. The step died, and the session did not care;&lt;br /&gt;
* &amp;lt;code&amp;gt;.4&amp;lt;/code&amp;gt; is the &amp;lt;code&amp;gt;kill-session&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Every attach is a new step, so you can count your own reconnects in &amp;lt;code&amp;gt;sacct&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Other ways it ends:&amp;#039;&amp;#039;&amp;#039; &amp;lt;code&amp;gt;scancel &amp;amp;lt;job ID&amp;amp;gt;&amp;lt;/code&amp;gt; ends it at once, and so does reaching the time limit, with your session and everything running in it. Save your work before the time runs out.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Be a good neighbour.&amp;#039;&amp;#039;&amp;#039; While the session exists, the job holds its cores and memory, whether you are using them or not, and nobody else can use them. Ask for an honest &amp;lt;code&amp;gt;--time&amp;lt;/code&amp;gt;, and close the session when you are done rather than leaving it to run out.&lt;br /&gt;
&lt;br /&gt;
== How it compares ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Approach !! Survives a lost connection? !! Survives a login node reboot? !! Ends cleanly with the job?&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; on the login node || yes || no || not a job at all&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; inside &amp;lt;code&amp;gt;srun --pty bash&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;sinteractive&amp;lt;/code&amp;gt; || no || no || yes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;salloc --no-shell&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;srun --jobid --overlap --pty bash&amp;lt;/code&amp;gt; || the allocation does, the shell does not || the allocation does, the shell does not || yes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;salloc --no-shell&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;ssh&amp;lt;/code&amp;gt; to the node + &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; || yes || yes || &amp;#039;&amp;#039;&amp;#039;not at the moment&amp;#039;&amp;#039;&amp;#039;: see the warning in [[Tutorials/Slurm-Interactive-Salloc|Part 3]]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;sbatch&amp;lt;/code&amp;gt; + &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039; (this page) || &amp;#039;&amp;#039;&amp;#039;yes&amp;#039;&amp;#039;&amp;#039; || &amp;#039;&amp;#039;&amp;#039;yes&amp;#039;&amp;#039;&amp;#039; || &amp;#039;&amp;#039;&amp;#039;yes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Try it yourself ==&lt;br /&gt;
&lt;br /&gt;
This makes a good exercise for a workshop.&lt;br /&gt;
&lt;br /&gt;
# Copy the script, add &amp;lt;code&amp;gt;#SBATCH --mem=1G&amp;lt;/code&amp;gt;, and submit it. Wait for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;squeue --me&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Attach, and start something long in the session, such as the clock above.&lt;br /&gt;
# Do not detach politely: close your terminal window, or switch off your Wi-Fi for a moment.&lt;br /&gt;
# Log in again and attach again. Is the clock still running? Did it miss any seconds?&lt;br /&gt;
# Open a second window in the session (&amp;lt;code&amp;gt;Ctrl-b c&amp;lt;/code&amp;gt;) and run &amp;lt;code&amp;gt;nproc&amp;lt;/code&amp;gt;. Does it match what you asked for?&lt;br /&gt;
# Close the session. Check with &amp;lt;code&amp;gt;squeue --me&amp;lt;/code&amp;gt; that the job has gone, then read &amp;lt;code&amp;gt;sacct -j &amp;amp;lt;job ID&amp;amp;gt;&amp;lt;/code&amp;gt; and explain every line.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
; &amp;lt;code&amp;gt;open terminal failed: terminal does not support clear&amp;lt;/code&amp;gt;&lt;br /&gt;
: &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; does not know what kind of terminal you have, because the &amp;lt;code&amp;gt;TERM&amp;lt;/code&amp;gt; variable is unset or set to &amp;lt;code&amp;gt;dumb&amp;lt;/code&amp;gt;. Most terminal programs set it for you. If yours does not, give it one when you attach: &amp;lt;code&amp;gt;TERM=xterm-256color srun --jobid=&amp;amp;lt;job ID&amp;amp;gt; --overlap --pty tmux attach -t work&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; &amp;lt;code&amp;gt;no server running&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;can&amp;#039;t find session: work&amp;lt;/code&amp;gt;&lt;br /&gt;
: The session has ended, and so has the job. Check with &amp;lt;code&amp;gt;squeue --me&amp;lt;/code&amp;gt;, and look at &amp;lt;code&amp;gt;sacct -j &amp;amp;lt;job ID&amp;amp;gt;&amp;lt;/code&amp;gt; for the reason (the time limit, for example).&lt;br /&gt;
&lt;br /&gt;
; The attach just waits, with no message&lt;br /&gt;
: You probably left out &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt; while another step is running in the job, for example because you are still attached in another terminal. Without &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt;, a new step waits until the cores are free, and it waits &amp;#039;&amp;#039;&amp;#039;silently&amp;#039;&amp;#039;&amp;#039;. We tested it: with a step already running, an &amp;lt;code&amp;gt;srun --jobid=... tmux ls&amp;lt;/code&amp;gt; without &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt; printed nothing for 20 seconds, until we stopped it. The same command with &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt; answered at once. (The &amp;lt;code&amp;gt;batch&amp;lt;/code&amp;gt; step itself does not block you. A first attach works even without &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt;. It is the second one that hangs.) Press &amp;lt;code&amp;gt;Ctrl-C&amp;lt;/code&amp;gt; and attach again with &amp;lt;code&amp;gt;--overlap&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Cheat sheet ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! You want to... !! Type&lt;br /&gt;
|-&lt;br /&gt;
| start the session || &amp;lt;code&amp;gt;sbatch tmux-work.sh&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| check it is running || &amp;lt;code&amp;gt;squeue --me&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| attach || &amp;lt;code&amp;gt;srun --jobid=&amp;amp;lt;job ID&amp;amp;gt; --overlap --pty tmux attach -t work&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| detach || &amp;lt;code&amp;gt;Ctrl-b d&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| end it and free the resources || &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt; in every window, or &amp;lt;code&amp;gt;tmux kill-session -t work&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| end it from outside || &amp;lt;code&amp;gt;scancel &amp;amp;lt;job ID&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Tutorials/Slurm-Interactive-Salloc|Interactive Slurm, Part 3: salloc — allocations and steps]]&lt;br /&gt;
* [[Tutorials/Slurm-Interactive-Shells|Interactive Slurm, Part 2: srun --pty bash and sinteractive]]&lt;br /&gt;
* [[Tutorials/Slurm-Interactive-Srun|Interactive Slurm, Part 1: srun]]&lt;br /&gt;
* [[Cancelling Jobs]]&lt;/div&gt;</summary>
		<author><name>Honfi001</name></author>
	</entry>
</feed>