Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Am doing some work on a remote centos 5.6 machine and my network keeps dropping. Is there a way i can recover my hung sessions after i reconnect?

EDIT: am doing some updating and installing with yum and am worried this might be a problem is processes keep hanging in the middle of whatever theyre doing

share|improve this question
2  
tmux or screen. – sehe Aug 23 '11 at 9:40

migrated from stackoverflow.com Oct 17 '11 at 16:01

3 Answers

up vote 11 down vote accepted

I like using tmux for this. I start tmux, start the operation and go on my way. If I return and find the connection has been broken, all I have to do is reconnect and type tmux attach.

Here's an example.

$ tmux
$ make <something big>
......
Connection fails for some reason
Reconect

$ tmux ls
0: 1 windows (created Tue Aug 23 12:39:52 2011) [103x30]

$ tmux attach -t 0
Back in the tmux sesion
share|improve this answer
dont have tmux, and am not allowed to install things not on my to do list... – sergio Aug 23 '11 at 9:44
1  
@sergio My heart bleeds :-)) Use screen. – cnicutar Aug 23 '11 at 9:45

You could try the screen command

share|improve this answer
from what i understand, i would have to have initiated yum with screen...welll, i didnt. i cant rerun yum it says its still being used and i dont want to force kill it. ..how can i regain control of the running yum? – sergio Aug 23 '11 at 9:41
and byobu is a nice complement to screen , to get it automatically launched in a nice graphical terminal launchpad.net/byobu – regilero Aug 23 '11 at 9:43
As far as I know you can't, unless there's some hidden way to redirecting the output from the yum command into your current term session but I can't think of one off the top of my head. – Nicholas Smith Aug 23 '11 at 9:44
There are a number of partial solutions to this using debuggers & c. to give a process a new parent shell. Reptyr is one, and a blog post describes the issue, the workaround and some other implementations. – Eroen Dec 7 '12 at 22:23

The recommendations for tmux and screen are both good suggestions. They imply the answer to your question, but don't actually state it. The answer to the question is: there is no way. If you login via ssh, the shell is ended when the connection drops. The work-around is to login and immediately start a virtual terminal of some kind (such as screen). When the connection drops, the shell you are in is ended, but you can open a new shell and reconnect to the virtual terminal (that is running the shell in which you are actually doing your work.)

share|improve this answer
Ok. its clear now. – sergio Aug 23 '11 at 9:46
Assuming the yum process still runs (didn't immediately terminate when the shell got SIGHUP), reptyr or similar might be sufficient to recover the process or --failing that-- obtain any future output. The shell would generally be terminated on disconnect, though. – Eroen Dec 7 '12 at 22:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.