Using Screen With Raspberry Pi
Reference
August 21, 2019
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:
- Connect to Pi via SSH
sudo apt-get install screen
- >>> it installs. reboot if necessary <<<
screen
space
orreturn
- >>> you’re in a
screen
session. start whatever scripts <<< ctrl + a
(release, then)d
→ detaches you from the session- >>> go about your business. shut down computer, turn off wifi, etc. <<<
- Connect to Pi via SSH
screen -ls
- >>> current
screen
sessions will be listed <<< screen -r
- >>> you’ll be reconnected to the session you left earlier <<<
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.