Using screen to leave processes running in a terminal

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

You might also like

Add colors to the text in terminal application in Mac OS X
Just add the following 2 lines to your /etc/profile, ~/.profile or ~/.bash_profile: export CLICOLOR=1 export...
Run a command from a Java application dealing properly with stdin, stdout and stderr
If you want to run an external command from a Java application you have to deal properly with the input,...
Fix black screen in Raspberry Pi with HDMI to VGA adapter
If you use an HDMI to VGA adaptor and get a black screen you may tweak the config.txt to solve the problem. If...
Using MacPorts php from command line
Some time ago I had installed Apache+MySQL using MacPorts in Mac OS X. It was all OK as long as I used...
Leave a comment ?

0 Comments.

Leave a Comment