Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a running job in a ssh terminal on an external server. I can pause it with CTRL + Z and resume it with fg. But I would like to pause it, run screen screen -S my_job and get it back in front with fg. It does not work. Is there a way to do something like this?

The reason is that my job is running quite a long time (1 month) and will run for two more months. If my desktop computer dies because of a blackout, my job will be killed.

share|improve this question

migrated from Nov 11 '11 at 5:40

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

Start your job inside screen. Then even if the connection fails you can reconnect to screen. – cnicutar Nov 10 '11 at 8:52
I know, but I forgot to do that a month ago. It is running at the moment. – Bjoernsen Nov 10 '11 at 8:59
Use retty or reptyr. – cnicutar Nov 10 '11 at 9:03
reptyr is working. Thanks. – Bjoernsen Nov 10 '11 at 9:15

The issue here is the controlling terminal of the job. I'm not aware of any method to change the controlling terminal, which you'd need to do if you wanted to move your program into a screen.

However, if your job has no important input or output on its standard input/output/error, you might consider the shell builtin disown, which removes a background job from the table of active jobs. This implies that the shell will not send the job a SIGHUP when it dies (e.g. due to connection failure of your ssh'ing host). Example:

$ long-running-job
$ bg
(shell displays backgrounding notification)
$ disown

And your job should run on. It's I/O will be closed, though, so that's no help if you have any stdin/stdout/stderr activity.

share|improve this answer
This is a good solution, thank you. But I think I am going to use reptyr. So I get the output of my job. – Bjoernsen Nov 10 '11 at 9:16

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.