Monday, April 9, 2012
11:06 PM

working with screen

If we start process from the command line in a terminal, when the terminal is closed the process also gets killed.

For e.g. let us try to open the gedit editor from the terminal



This will launch the editor, allowing us to wrok on the editor. Now if we close the terminal from where we ran the command, the editor also closes with it.

But there might be situations when we want the processes to keep running evern after the terminal is closed. This can be achieved by using the command screen, screen not only allows us to continue with the process even after the terminal is closed it also allows to attach another session of the screen to the process and regain control over it.

Let us see how to do this with an example.

Open a terminal and type the command screen

Note: If screen not installed in the system we will have to download it using the pacakge manager. In debian based systems we can run the command.



to install screen.

The command displays the version of the screen and other related information, hit enter to get back to the terminal. The new terminal that is presented to you is the terminal of the screen command. Let us open an editor in this new terminal



Once the editor has launched, we can close the terminal from which we launched the editor, unlike the previous case the editor will not get closed with the terminal this time. Next we need to regain control over the gedit process, this can be done in a new session of screen.

Open a new terminal and run the command



The string "2627.pts-0.user" gives us the information regarding a process which was running in a screen but has been detached in our case it is the gedit process. The first number "2627" is the pid, the second "pts-0" is the terminal number and the third "user" is the host who launched the process.

Thus if you have more than one process which was launched in different screens and have got detached all of them will get listed as a result of the above command and we can recognize the process we are intersted in by looking at the pid.

To reattach the process run the command



Now you should have new terminal with the same command "gedit temp" in it.

Thus any process can be dettached and attached to a screen with out stopping it.

0 comments:

Post a Comment