Monday, January 12, 2015

Keep running process : screen

Screen is a utility tool to keep running your process despite of dropped connection. 
There are following commands which are useful . These commands begin with 'CTRL+a' to distinguish them from normal shell commands.
Ctrl a c - Creates a new screen session so that you can use more than one screen session at once.
Ctrl a n - Switches to the next screen session (if you use more than one).
Ctrl a p - Switches to the previous screen session (if you use more than one).
Ctrl a d - Detaches a screen session (without killing the processes in it - they continue).
To close a screen session where all tasks are finished you can type exit to close.

To check the current screens on server with status. use screen -ls
[root@MYSYS001 ~]# screen -ls
There is a screen on:
        16495.pts-6.MYSYS001    (Detached)
1 Socket in /var/run/screen/S-root.

To connect a detached screen use command screen -r
[root@MYSYS001 ~]# screen -r 16495.pts-6.MYSYS001

When you detach your session using 'Ctrl+a' + d, below message will appear
[detached]

If a screen is attached following message will appear
[root@MYSYS001 ~]# screen -ls
There is a screen on:
        16495.pts-6.MYSYS001    (Attached)
1 Socket in /var/run/screen/S-root.

Trying to attach a already attached screen, you will found following message
[root@MYSYS001 ~]# screen -r 16495.pts-6.MYSYS001
There is a screen on:
        16495.pts-6.MYSYS001    (Attached)
There is no screen to be resumed matching 16495.pts-6.MYSYS001.

No comments:

Post a Comment