Sunday, August 14, 2011

Screen command tips

Screen is a full-screen window manager for the terminal mode. It is best known for multiplexing a single terminal across several processes. By using it, you can run many number of commands within a single terminal.

1) First open a terminal and type :

$ screen

2) Screen starts and creates a new single window with a shell.

New windows can be created within the same terminal using the screen command.

3) Now you started screen in a terminal, suppose you want to run the 'top' command to check the System load and at the same time you want to ping a ip -
For that, first execute the first program to be run (say 'top'). now 'top' will start in the terminal.
Now open a new window in screen by pressing the '[Ctrl + a] c' - which I will state as 'C-a c' . This will create a new window in the same terminal. Here, you can give commands to compile your program.
In screen, each window is given a unique identifier. The first window is numbered 0, the next window is 1 and so on. Now to switch between your 'top' and the ping, you can use the key 'Ctr+a 0' and 'Ctrl+a 1' respectively.

You can also log out from the machine and re-login. Then start any terminal session and type 'screen -r' to once again be connected from where you left.
In case, there were more than one screen sessions running on the machine, Screen prompts for a host.tty.pid.
For example, say I have two screen sessions. So when I type 'screen -r' command, it gives the following message:

$ screen -r
There are several suitable screens on:
2999.pts-6.localhost (Detached)
1920.PTS-6.localhost (Detached)
Type "screen [-d] -r [pid].tty.host" to resume one of them.