I'm really new to linux (like earlier this week is when I started) so excuse me if this is a really simple question. I am running a program on a remote server and it's a lengthy process dealing with a couple hundred gb of data so I wanted to leave it running overnight. Long story short I ssh in, I start the program, watch to see that it's running and then close out of terminal. I come back this morning and see it stopped exactly where it was when I terminated my ssh the night before. Is there a way to keep the process running on the server when I close out?
4 Answers
As the other answers suggest. You can use nohup <command> &
.
You can also use screen
, this (basically) is a detachable terminal. You can start a terminal using the command screen
and when you want to detach from it. Ctrl+ad. And to reattach your terminal run screen -r <terminal_name>
. If you have more then one detached terminal's, you can use the command screen -r
to see the names of the detached terminal's.
Screen is a full-screen window manager that multiplexes a physical ter‐ minal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.
EDIT:
You can also use tmux
. Have a look here for a basic "how to use tmux
".
tmux
is a terminal multiplexer. What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

- 333,661

- 8,954
The command you want is called nohup
. Basic syntax is:
nohup <command>
This will run <command>
and forcibly ignore SIGHUP (the signal sent to processes when their controlling terminal is closed, such as when the parent SSH session ends). Note that it is possible on a Systemd based system to prevent this from working, but no distro I know of uses such a configuration by default.
Alternatively, check if the command at
is present and atd
is running. If both are the case, you can tell the system to run your script as a batch job and possibly even e-mail you the output by using the following:
at "`date +%FT%T`" << EOF
<command>
EOF
You can substitute the contents of the double quotes for any reasonable date and time specification (at
is smart enough to handle reasonably human readable stuff like '8AM tomorrow' or 'next sunday'), but the given command will start the job immediately (the date command will return the current date and time as an ISO 8601 timestamp).

- 11,867
You can use nohup
in this case.
Try
$ nohup ./YourExecutableFile &
This will run your executable file and put it in the background and it wont stop even if you logout.

- 8,954

- 317
Login to your server over SSH and run:
nohup YOUR_PROGRAM &
This will run your program in background and running process won't stop if your SSH session will disconnect and stop shell you were using.
Check out this thread for details about nohup
and &
.

- 2,003
jobs
command will only list jobs started in the current shell. If you start a job withnohup
and then log out, then thejobs
command would not list them (but the may still be running). I would suggest usingscreen
instead, it's a lot more versatile. – Kusalananda Apr 13 '18 at 10:14