On the command prompt, type screen. Run the desired program. Use the key sequence ctrl-a + ctrl-d to detach from the screen session. Reattach to the screen session by typing screen -r.
$ screen -listor
$ screen -ls$ screen$ screen -S <session_name>$ screen -r <session_name>$ screen -x <session_name>[ec2-user@ip-111-222-333-123 ~]$ screen -ls
There are screens on:
2004.pts-0.ip-111-222-333-123 (Detached)
2042.pts-0.ip-111-222-333-123 (Detached)
2 Sockets in /var/run/screen/S-ec2-user.
[ec2-user@ip-111-222-333-123 ~]$ screen -r 2004
[detached]
[ec2-user@ip-111-222-333-123 ~]$ screen -r 2004
[screen is terminating]
[ec2-user@ip-111-222-333-123 ~]$ screen -r
[screen is terminating]
[ec2-user@ip-111-222-333-123 ~]$ screen -ls
No Sockets found in /var/run/screen/S-ec2-user.
[ec2-user@ip-111-222-333-123 ~]$ screen -S executeLongTimeJob
[detached]
[ec2-user@ip-111-222-333-123 ~]$ screen -ls
There is a screen on:
2456.executeLongTimeJob (Detached)
1 Socket in /var/run/screen/S-ec2-user.
[ec2-user@ip-111-222-333-123 ~]$ screen -S anotherLongTimeJob
[detached]
[ec2-user@ip-111-222-333-123 ~]$ screen -ls
There are screens on:
2493.anotherLongTimeJob (Detached)
2456.executeLongTimeJob (Detached)
2 Sockets in /var/run/screen/S-ec2-user.
[ec2-user@ip-111-222-333-123 ~]$ screen -r anotherLongTimeJob
[screen is terminating]
[ec2-user@ip-111-222-333-123 ~]$ screen -r
[screen is terminating]