Skip to content

Instantly share code, notes, and snippets.

@MahdadGhasemian
Created March 9, 2026 11:08
Show Gist options
  • Select an option

  • Save MahdadGhasemian/e2e47db1f5e3615ae2acb1be9475d6c6 to your computer and use it in GitHub Desktop.

Select an option

Save MahdadGhasemian/e2e47db1f5e3615ae2acb1be9475d6c6 to your computer and use it in GitHub Desktop.
Screen: Never Lose a Process Again

Screen: Never Lose a Process Again

If you’ve ever started a long-running task—like a database migration— only to have your terminal or SSH connection drop, screen is your lifesaver. It keeps processes running in the background so you don’t have to babysit your terminal.


1. Create a Session

Start a named session so you can easily reattach later:

# db_migration is just a name here
screen -S db_migration

2. Run Your Long Process

Inside the session, start your process:

python3 migrate_database.py

3. Detach and Let It Run

Detach the session without stopping your process:

Press Ctrl + A, then D

Your process keeps running even if you close your terminal or your network drops.


4. Reattach Later

Reconnect to your session anytime:

screen -r db_migration

5. Fully Exit

When your task is done and you’re finished with the session:

Press Ctrl + D to terminate the session.


✨ Why this is magic: Your scripts, migrations, or backups keep running safely in the background, even on weak or flaky networks.

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