Apollo Connecting the World

Diligence and Intelligence

Maintain the Program Running on the Remote Machine while Network Is Not Persistent

leave a comment »

Let’s take this scenario:

You ssh to a remote machine and work (eg. run programs). When a network error occurs that you lost connection to the remote machine, your work will be interrupted in half way, and even worse, your work will be lost without being stored. What you have to do is ssh to that machine again and do the work again. So the following question rises:

How to preserve my work in remote machine while connection failure is possible?

The solution is simple. Use a program “screen” in the remote machine.

When ssh to remote machine, before you want to run any programs or do other work, you first type “screen” to open a screen. The function of the screen is that, it provide you with a new terminal, in which you can do you work as usual in a ordinal terminal, however, the work in screen is safe if you lost connection to the remote. If you ssh again, and use screen to the previous job, you will see your work is preserved. You can continue your work easily.

Some cmd for screen:

1. detach (temporarily go out of the screen): Ctrl+a, d

2. see the detached screens: screen -list (or: screen -ls). You will get all the screens, in a form of [pid.tty.host]

3. re-attach to the screen: screen -r tty (or: screen -r pid.tty.host)

Reference:
1. http://www.ibm.com/developerworks/cn/linux/l-cn-screen/

Written by apollozhao

2010/04/30 at 12:38

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: