forked from dtamayo/dtamayo.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.html
More file actions
149 lines (133 loc) · 6.98 KB
/
screen.html
File metadata and controls
149 lines (133 loc) · 6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Dan Tamayo</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/landing-page.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand topnav"></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="research.html">Research</a>
</li>
<li>
<a href="group.html">Group</a>
</li>
<li>
<a href="resources.html">Resources</a>
</li>
<li>
<a href="sandbox.html">Sandbox</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Header -->
<div class="intro-header"></div>
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="main-section-heading">Keeping a terminal session running with the screen command</div>
</div>
</div>
</div>
<div class="container">
<div class="row topbot-buffer">
<div class="col-lg-12">
<p class="lead">
While there are other applications, the most common problem this solves for me is when I log into a workstation remotely to start a jupyter notebook, and want to leave it running (to finish a set of runs, or just to leave it up so I can pick up where I left off when I have to work on things throughout the week). The problem is that the process running our jupyter notebook will terminate as soon as our ssh session ends. We can prevent that by using the screen command. Once you've ssh'ed into the workstation you want to use (i.e., we want to run the jupyter notebook on the workstation, not on our own laptop!), the trick is to start a new screen session before launching jupyter notebook:
</p>
<pre>
<code>
screen -S danjupyter
jupyter notebook
</code>
</pre>
<p class="lead">
The first command starts a new screen session, and names that screen session 'danjupyter' (you may need to choose another name if someone has already used that). The second starts a jupyter notebook as usual. Once that is running, you hold Ctrl + a, and while holding those keys, press d. This detaches your screen session, and you get back your original ssh session with your screen session now running in the background. Now you can close your terminal window (which will end your ssh session), or even shut down your laptop, and the screen session will continue running on the workstation in the background. You can google screen commands, but useful ones include
</p>
<pre>
<code>
screen -r danjupyter
</code>
</pre>
<p class="lead">
to reconnect to your running screen session called 'danjupyter' (can replace with whatever you chose to call it). This is useful to close jupyter notebook after you're all done (Ctrl + c). If you're done with the screen session, you can end it by typing
</p>
<pre>
<code>
exit
</code>
</pre>
<p class="lead">
This will take you back to wherever you were / whatever machine you were on when you started the screen session. To check the names of all screen sessions currently running in the background you use
</p>
<pre>
<code>
screen -ls
</code>
</pre>
<p class="lead">
If you want to kill a screen session that's running, you need to know the name of that session, or use the above command to get the number that's in front (e.g., 20351 in 20351.jupyter). Then
<pre>
<code>
screen -X -S danjupyter kill
</code>
</pre>
</p><p class="lead">
where you would replace 'danjupyter' with the name (or number) of the screen session you want to kill. This can be useful in cases where you get mixed up with the commands above, and it won't let you reconnect to a screen session because it says it's already attached (and you want to start over, killing anything that's running in it).
</p>
</div>
</div>
</div>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-12">
<p class="copyright text-muted small">Copyright © Dan Tamayo 2026.</p>
</div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>