If you are using an SSH connection and run a command that takes very long to process you can use nohup
to prevent that process to be terminated when you logut from the SSH session:
nohup command > /dev/null 2>&1 &
But using this method detaches the process from stdio, stdout and stderr (unless you redirect them somewhere, as previous example redirected them to /dev/null
). If you want to be able to reattach to that process later on screen
is the right tool.
Firt install screen
:
sudo apt-get install screen
Then run a bash shell using screen
:
screen bash
A new shell wil be openen and the you can run anything you want. Lets supose you start converting a huge video to another codec. Once the process has started you have to press CTRL+A and then D to detach from that shell. Now you’ll be back to the original shell but the video process will still be running.
If you have only one screen
process running you can reattach to it by just running this:
screen -r
If you can have multiple screen
processes at the same time you have to specify to which of them you want to attach. Using this command will tell you the names and some more info about all current screens:
screen -list
Then you can attach to them using that name:
screen -r name
If you want to terminate a screen
process just attach to it and press CTRL+D.
Source: http://raspi.tv/2012/using-screen-with-raspberry-pi-to-avoid-leaving-ssh-sessions-open
0 Comments.