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 know of terminating a command with & and then moving it into the background by pressing Ctrl-Z and then bg [pid], and I also know of nohup.

But say you started a process that turned out to take much longer than one expected, is there a way of pulling, so to speak, this process from another terminal screen into the background so that even if I log off from the server the process would continue?

share|improve this question

2 Answers 2

up vote 0 down vote accepted
  • Suspend it:

    CtrlZ

  • restart in background:

    bg
    
  • and tell the shell to not kill it on logout (SIGHUP):

    disown
    

    Note: Plain disown removes the job from the shell's jobs list completely, while disown -h just marks it as "do not kill on logout" but leaves on the list.

share|improve this answer
    
You can do this mid-process? Take this for an example. I have a FreeNAS box and I mount the old Windows share, then I start copying from the old to the new only to find out that copying 1 TB over a 100Mb network is taking longer than I'd like. Could I do what you just described AFTER starting the copy? –  Mustafa Ismail Mustafa Jan 18 '11 at 15:15
    
@Mustafa: Yes, that's precisely what I described. (You do already know the meaning of Ctrl-Z and bg, don't you?) –  grawity Jan 18 '11 at 15:20
    
Yeah, I didn't know about disown though. Many thanks :) –  Mustafa Ismail Mustafa Jan 18 '11 at 15:42
    
Another thing. Is there any way I can "re-own" a process? Or am I asking for too much? –  Mustafa Ismail Mustafa Jan 18 '11 at 16:52
    
@Mustafa: You cannot. (There are tools such as retty, but they don't work well.) Next time, run the program inside tmux/screen/dtach, but for now you'll have to live with it. –  grawity Jan 18 '11 at 19:05

Always run "screen" when you first login. Look into https://launchpad.net/byobu I use byobu to automatically start a screen session whenever I log in. That way, I automatically have screen running and I can disconnect the session or start a new window whenever I need it.

share|improve this answer
    
Nice! I sorta knew that there should be something like that. Good to know I'm not the first one in the world to encounter something like this :p But nothing that would do what I said? I'm backing up VMs and the smarty that I am didn't realize that they're in excess of 1 TB :s –  Mustafa Ismail Mustafa Jan 17 '11 at 20:15
    
I don't know of a way to do exactly what you ask. –  edgester Jan 17 '11 at 20:20
    
Thanks in any case :) –  Mustafa Ismail Mustafa Jan 18 '11 at 15:13

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.