Golden Codes - armanexplorer planet

Practical code snippets for Django, Python, Bash, Git and All!

View on GitHub

de-attach process from shell

There are a couple of ways to SSH into a Linux server, run a process, and detach it from the SSH session:

1. Using tmux:

2. Backgrounding and Disowning:

3. Using nohup:

Remember, choosing the right method depends on your specific needs and preferences.

using disown

Example:

jupyter notebook --no-browser & disown

# in zsh (&! is zsh built-in function that does the same as & disown)
jupyter notebook --no-browser &!

jupyter notebook & >> disown

using nohup

nohup jupyter notebook --no-browser &

compare nohup and disown

Disown vs. nohup: Detaching Processes from SSH

Both disown and nohup help you run a process on a remote server via SSH and keep it running even after you disconnect your SSH session. However, they achieve this in different ways:

disown:

ssh server_name  # Connect to server
my_long_process &  # Run the process in background
disown %1          # Disown the last background job (replace %1 with actual job number if needed)

nohup:

ssh server_name  # Connect to server
nohup my_long_process &  # Run the process with nohup and background it

Choosing Between disown and nohup:

Additional Notes:

find process

pgrep jupyter

ps -ef| grep jupyter