I am running Mathematica on a remote Linux cluster, by the terminal, using the math
command. (I do not have access to a terminal GUI. For example, when I type the command mathematica
, I get this error message: Can't open display ""
.)
I write Mathematica code in a text file (e.g., test.txt
) and pass it to math
using either the command
math < test.txt
or the command
math -script test.txt
Both of these methods work fine for starting a Mathematica job. However, when I log out of the terminal -- or even when a brief loss of internet connection interrupts my connection to the remote cluster -- the Mathematica script is terminated. When I log back in the terminal, no Mathematica processes (i.e., MathKernel
) are running.
To prevent this termination upon logout, I have tried using the standard Linux program nohup
, which is a command telling the terminal to ignore the HUP
(hangup) signal; output is redirected to a file nohup.out
. I use nohup
with any of the following commands:
nohup math < test.txt
or
nohup math < test.txt &
or
nohup math -script test.txt
or
nohup math -script test.txt &
These commands all start the Mathematica job fine, but when I logout and log back in to the terminal, no MathKernel
or similar processes are running (as verified by ps
and by ps -u myusername
). The situation is the same regardless of whether my job is a single kernel job or a parallel, multikernel job. Since the jobs start fine -- including those ending with the &
symbol to force the job to the background -- I do not think that I am having the same "background job suspension" problem as in this question.
Do you have any thoughts on how I can prevent the terminal from terminating jobs when I logout or my connection is briefly interrupted? The nohup
method above works for me with other programs, but for some reason not with Mathematica.
(A toy test example is Table[Length[FactorInteger[10^50 + n]], {n, 50}]
, which takes about 30 seconds on the terminal.)