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
- To Enter Into Screen Session Just type “screen”
2. To detach from screen type ctrl and a then d “ctrl+a -d”
3. To list Out screen “screen -ls”
4. Create Screen session with screen name “screen -S <name of screen>”
5. Resuming on screen with process id and name of screen “screen -r <pid>”and for name “screen -r <name of screen>”
6. Remove Screen Session “ screen -X -S <pid or name>”
7. Create New Window in the screen “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
- I am logged In To My Server Using SSH In Two Terminal Both Using Same User Account And Using Same Remote Machine As Shown
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
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
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.
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
- After login type screen and then run python a.py in screen in terminal 1as shown
2. Now Again Check For Process id in Terminal 2
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 .
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.