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 process running on my Linux machine (Debian squeeze) that takes hours (or days) to finish.

I don't want to stop it to restart it again with screen, tmux or with an output redirect to nohup.

Is there a secure way to put it in the background with ^Z and bg so it will continue once I close the ssh-session?

share|improve this question

migrated from stackoverflow.com Oct 9 '12 at 10:17

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

    
what do you mean by "stop it to restart it again with screen,tmux.."? if you start a tmux/scrn session via ssh, it will keep alive if you close your ssh connection. –  Kent Oct 8 '12 at 13:29
    
the process is already running and lasting for some hours, but i cannot stop it or i will loose data. –  rubo77 Oct 8 '12 at 14:46
    
If the command is already running, I don't think there's a way to accomplish this. There are, however, numerous ways to do it in the future if you run it under screen, dtach, tmux, etc. as you already note, or with appropriate redirections and nohup. You might be able to ^Z, bg it now, but whether that's enough depends on whether it does I/O on the terminal after you background it. –  twalberg Oct 8 '12 at 14:58

1 Answer 1

up vote 7 down vote accepted

use

commandtoexecute &> /dev/null &

it will run your process in the background, and prints all output to /dev/null.

Replace /dev/null with another file to see the output.

e.g. commandtoexecute &> /tmp/file1 &

use tail -f /tmp/file1 to attach to output again

You can also redirect stdin, see this http://www.tuxfiles.org/linuxhelp/iodirection.html

If you want to detatch from a process that is allready running. Use disown <pid> where pid is your process id.

You could also change the terminal to another terminal:

  1. start a screen
  2. get pid of your process
  3. run reptyr <pid>
  4. detach using CTRL+A+D

reptyr: http://serverfault.com/a/284795

share|improve this answer
    
I would add 2>&1 to see the error output too. –  EarlGray Oct 8 '12 at 14:04
2  
&> redirects all output :D –  Eun Oct 8 '12 at 14:05
    
thx, that would be the right start in the first place. But you didn't read my question: the process is already running and cannot be started over with your additions –  rubo77 Oct 8 '12 at 14:47
    
ok, edited, check my answer –  Eun Oct 8 '12 at 14:52
1  
brings me to this: serverfault.com/a/284795, Start a screen, run reptyr with pid and detach –  Eun Oct 8 '12 at 15:32

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.