Skip to content

Instantly share code, notes, and snippets.

@samsammurphy
Created May 15, 2019 13:38
Show Gist options
  • Select an option

  • Save samsammurphy/b966b46cd0fd73c581b50f69ce515f57 to your computer and use it in GitHub Desktop.

Select an option

Save samsammurphy/b966b46cd0fd73c581b50f69ce515f57 to your computer and use it in GitHub Desktop.

You can use screen.

sudo apt install screen

Screen allows you to run processes inside of it and leave the process running even if your pipe automatically breaks or you leave the EC2 instance.

When you connect back screen will have kept your processes running.

Here is how to use it..

PART 1 Running a big process in the cloud

1) ssh into server (or practice locally first)

2) start screen

$ screen

# press return to get back to terminal

3) run a command

$ htop

4) create a new screen

Ctrl+A then Ctrl+C

# swap Ctrl for Cmd if you have a mac

4) run another command

$ echo 'running my big process here..'

5) split the screen (vertically)

Ctrl+A then |

6) move cursor between split screens

Ctrl+A then Tab

7) move to next screen

Ctrl+A then Ctrl+N

8) detach from screen and let commands keep running

Ctrl+A then Ctrl+D

9) disconnect from server

exit

PART 2 Reconnecting to the process

1) re-connect by ssh

2) list screens

screen -ls

3) re-attach to screen

screen -r {id}

# {id} only required if you ran the screen command multiple times

4) check out your screens

Ctrl+A then Ctrl+N

5) exit the screens

exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment