Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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
2  
Use retty or reptyr. –  cnicutar Nov 10 '11 at 9:03
    
reptyr is working. Thanks. –  Bjoernsen Nov 10 '11 at 9:15

1 Answer 1

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
^Z
$ 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

 
discard

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.