deepak kathuria
4 min readOct 17, 2021

--

GNU SCREEN

GNU Screen Is A Terminal Multiplexer,Terminal Multiplexer Allow You To Keep Process Running Even If You Close The SSH Connection So For Example We Have Long Running Job We Have To Run Over Night And You Don’t Want To leave Your Machine “On” But You Are Running It On Remote Server So You Use Screen Concept Which is A Type Of Terminal Multiplexer. GNU screen Allow You To Run the Process Or Job Running In Background Even On Connection Closed .

Gnu Screen is Terminal Multiplexer That Can Be Used To Multiplex Several Virtual Consoles ,Allowing User to Access Multiple Login Session Inside Single Terminal Window.

COMMANDS

  1. To Enter Into Screen Session Just type “screen”
I am in screen and written simple hello world

2. To detach from screen type ctrl and a then d “ctrl+a -d”

detached from screen or move out from screen session

3. To list Out screen “screen -ls”

list of screens

4. Create Screen session with screen name “screen -S <name of screen>”

screen session with name deepak is created

5. Resuming on screen with process id and name of screen “screen -r <pid>”and for name “screen -r <name of screen>”

resuming to screen session or reattaching to screen session with name or pid

6. Remove Screen Session “ screen -X -S <pid or name>

remove screen sessions

7. Create New Window in the screen “ctrl +a -c

I have created 5 window in screen byb pressing ctrl+a -c

8. To move move forward and backward through window “ctrl +a -n” n is for next

ctrl+a -p” for previous window

ctrl+a 0” 0 represent window number

“ctrl+a \” not work for me kill all windows in screen

ctrl+a A” not work for me renaming window in screen

GNU SCREEN TO KEEP PROCESS RUNNING WITHOUT LEAVING MACHINE ON OR CONNECTED

PROBLEM WITHOUT SCREEN MULTIPLEXER

  1. I am logged In To My Server Using SSH In Two Terminal Both Using Same User Account And Using Same Remote Machine As Shown
TERMINAL 1
TERMINAL 2

2. Creating Python Script a.py In Terminal 1 As shown And Run This It will Take Too Much Time To Run As we are running 300 times hello world with time.sleep of 2 means 2 second break in each time

a.py
a.py script running on terminal 1

With Running Terminal1 script We Go To 2nd terminal we Run ps command to see the “pid” of script running on remote server from terminal 1

pid =4375

Now with 1 terminal we disconnect or close the terminal 1 and again see the process which are running we saw that process is also terminated after losing or closing the connection as shown even we have connection with the same user with terminal 2 to same remote server.

we have no process running pid=4375

THIS PROBLEM IS SOLVED USING SCREEN AS SHOWN

Now We open terminal 1 and the login again with ssh and then we use screen to solve the problem

  1. After login type screen and then run python a.py in screen in terminal 1as shown
script is running in terminal 1 using screen

2. Now Again Check For Process id in Terminal 2

pid=4540 which is running using screen in terminal 1

3. After Loosing the Connection from terminal 1 where screen is running and our a.py script is running and then again we check for process in terminal 2 and now we saw that process is still running .

4540 still running after closing terminal 1 because we run the script in screen

4. After that go to terminal 1 again and login and then type

<screen -r >

It will shows that our script is running in the background So with the help of screen we can run processes in background even after closing the window or connection lost.

--

--