Categories
#DEV

Run Tasks/Jobs in the Background while closing the SSH Session

We usually run imports and exports for our email marketing software using PHP-CLI (Command-line Interface). The problem comes when we want to work on something else. Instead of opening multiple terminal sessions, we use this little application called Screen. This little application is quite handy when it comes to keeping those sessions alive by running tasks/jobs in the background. Screen is a console application that allows you to have multiple terminal sessions within a single window.

If you don’t have it installed, you can install it by using the following command:

sudo apt-get update
sudo apt-get install screen

To use:

screen -dmSL [session name] [commands]

d – starts a session and immediately detaches from it
m – forces the creation of a new session
S – lets you give the session a friendly name
L – turns on logging to ~/screenlog.0

To detach and keep the processes running:

Ctrl + A + D

To resume the session:

Screen -x "session-name"