How do I keep a process running after I disconnect from my Linode?
I want to run a Bash command and keep it running when I log off of my Linode. What are my options for doing this aside from setting the command up as a daemon?
2 Replies
There are a couple of methods for accomplishing this. You could use nohup $restofcommand &. Ending the command with the & places the command in the background so you can end your session while it runs.
You could also use the bg command as follows:
- Run the command normally
- CTRL + Z
- Run
bg - Type
disown - Exit the terminal
The nohup method is typically the more natural route, but either will work :)
You could also run the command in a tmux or screen session, detach from the session, then disconnect from your Linode. The command will continue to run in the session.
tmux method
Start a tmux session:
tmuxRun your command or script in the tmux session.
Detach from your tmux session:
tmux detachor enter Ctrl+B, then DYou can later resume the session:
tmux attach
screen method
Start a screen session running your command:
screen $commandDetach from your screen session: Ctrl+A, then Ctrl+D
You can later resume the session:
screen -r
systemd method
If you want to go even further beyond and have your command persist through reboots, you could use systemd to configure, start, and enable a service based on the command. You can find instructions on how to accomplish this in our guide: