Using Screen With Raspberry Pi

How-To Reference

Today I got acquainted with screen, a process manager (?) for Linux that is very useful with Raspberry Pi

Before today, I could only run programs on Pi if my computer is also up and running—I don’t have any reliable peripherals so my only way of operating Pi is via SSH, and an optional remote desktop server for the GUI. I’m using Pi mostly to take photos for a time lapse which means there’s a script running pretty much around the clock. In order for it to keep going, that meant I couldn’t shut down my laptop…ever!

Screen To The Rescue

…Until screen. This library lets you open a new session in Pi and run commands & scripts from there. However there’s a huge difference between the screen session and your normal SSH session, because you can detach it and it will keep running! And thus my laptop has become a portable machine again.

How To Work With screen

These three articles helped clarify the steps, but to summarize:

  1. Connect to Pi via SSH
  2. sudo apt-get install screen
  3. >>> it installs. reboot if necessary <<<
  4. screen
  5. space or return
  6. >>> you’re in a screen session. start whatever scripts <<<
  7. ctrl + a (release, then) d → detaches you from the session
  8. >>> go about your business. shut down computer, turn off wifi, etc. <<<
  9. Connect to Pi via SSH
  10. screen -ls
  11. >>> current screen sessions will be listed <<<
  12. screen -r
  13. >>> you’ll be reconnected to the session you left earlier <<<
  14. ctrl + d → disconnects the session & all running processes

There are some more options available which can be found in the docs and posts linked above. You can operate multiple sessions, customize them, and more.