Take the 2-minute tour ×
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

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

This question came from our site for professional and enthusiast programmers.

tmux or screen. –  sehe Aug 23 '11 at 9:40

4 Answers 4

up vote 17 down vote accepted

There is no way, but to prevent this I like using tmux. 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

$ 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
@sergio My heart bleeds :-)) Use screen. –  cnicutar Aug 23 '11 at 9:45

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

As William said, the short answer is no, there is no way. To prevent this you could use the screen command before you lose connection

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

No, you can't recover a shell after a disconnection. Instead what you can do is ensure the command you were running continues to run after the disconnect.

To achieve this, use "nohup" and "disown" commands, which are usually builtin commands on most shells, i.e. you don't need to install anything. This only works for non-interactive commands though.

So, the steps would be as follows:

  1. Login to server
  2. Run your command: "nohup sudo yum update &" (this will also log all output to nohup.out file in your current directory)
  3. Run "disown %1"
  4. Feel free to disconnect at this point or wait to be disconnected :)

When you come back to the server, simply "tail nohup.out" to see how the command is doing.

share|improve this answer
Wouldn't this work pretty poorly in the general case? For example, with commands that want input at one time or another... For completely non-interactive commands, it might work well enough and avoid the overhead of (and possibly needing to install) a terminal multiplexer. –  Michael Kjörling Sep 17 '13 at 14:11
Yes, this only works if your commands don't want any user input, I've updated the answer. Overall a terminal multiplexer is the way to go for sure, but it was mentioned that no additional tools were permitted to be installed. –  zygis Sep 17 '13 at 15:03
Absolutely, it's a valid answer, just slightly limited in its possible use cases. Upvoted with the edit. –  Michael Kjörling Sep 18 '13 at 7:29

Your Answer


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