This post assumes that you have a project and a virtual machine (VM) instance already set up at Google Cloud Engine.
It easy to connect to your VM instance via SSH by clicking on the
SSH link on the webpage. However, the tasks will be terminated when the SSH connection is terminated.
Instructions are provided below to keep the tasks running even after SSH connection is lost. In the intsructions below, we will use an example of running a
python example.py script.
Run a program with a
screen to keep it running when you log out of your SSH session:
- First, connect to your VM instance via SSH terminal
screeninside your compute instance:
sudo apt-get install screen
- Then, run:
screen python example.py
A new screen will be created where the output of
python example.pywill be printed.
- Detach this screen, to return to your SSH terminal, while the
python example.pycontinues to run on the detached screen. To detach, enter
Ctrl+a then Ctrl+d
- Feel free to close or leave your SSH terminal
- To resume, login into your VM instance via SSH terminal and reattach to the previously detached screen. List all screens using
screen -lsand to reattach to a desired screen, enter
screen -r [screen name]
- To kill a detached screen:
screen -X -S [screen name] quit
- To kill an attached screen: