(1) ssh into your machine
(2) install with sudo apt install screen
or sudo brew install screen
depending on OS
(3) run screen and name it screen -S dummyscreen
S = Session name
(4) execute the program you wish to run in the background, this can be a server, a cron job, whatever use case you have in mind
(5) to detach the screen
session without stopping the processes on the remote server, press Ctrl-A + D
, this leaves the screen
session running in the background
(6) view screen sessions with screen -list
(7) to attach back to the session run screen -r dummyscreen
r = Reattach
(8) close a session screen -XS dummyscreen quit
X
= Execute command, S
session PID/session name to execute on
While running a long running process on your remote server, you go afk, after coming back to the terminal session you notice “Write Failed: Broken Pipe”.
You want to run a program in the background on your remote server.
Screen isolates terminal-launched programs, enabling session detachment/attachment.
By using screen, you're essentially creating a persistent session that enables you to reconnect to it, even if the network connection to the remote server is disrupted. This keeps your remote processes running despite network issues and prevents interruptions due to "Broken pipe" errors.