How do I keep a process running after I disconnect from my Linode?

Linode Staff

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:

  1. Run the command normally
  2. CTRL + Z
  3. Run bg
  4. Type disown
  5. 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

  1. Start a tmux session: tmux

  2. Run your command or script in the tmux session.

  3. Detach from your tmux session: tmux detach or enter Ctrl+B, then D

  4. You can later resume the session: tmux attach

screen method

  1. Start a screen session running your command: screen $command

  2. Detach from your screen session: Ctrl+A, then Ctrl+D

  3. 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:

Use systemd to Start a Linux Service at Boot

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct