Keep Running
How to keep your command running?
Here I introduce two ways to keep your command running in the background. You need this when:
Run a command (e.g., downloading a large file) that takes a long time to finish.
Run a command in the background for a long time, for example, a jupyter notebook server.
SIGHUP
When you execute a command in the terminal, it will block other commands until it finishes. If you close the terminal during the execution, the command will terminate also. Because a SIGHUP will be sent to that process (the executing program), and terminate it. Below prevent this from happening even you close the terminal.
Run with nohup and &
nohup
is a simple way to keep your command running, it means "no SIGHUP", so if you use nohup
in front of a command, closing terminal will not terminate the command.
"&" means put the process will be put in the background, so it will not block terminal, and you can execute other commands in this same terminal.
Check out fg
, bg
, and jobs
command again here.
Screen
screen
is an even better way. It can create named terminal screens, which will keep running independently to your terminal. Here are a few examples
I will leave other usages of screen
as homework, you can quickly learn this from google and youtube since you now know what to search 😏.
How to terminate a screen?
What's other options to control a screen when you press Ctrl+A in a screen?
Last updated
Was this helpful?