8

Possible Duplicate:
How do I detach a process from Terminal, entirely?

I've a program running in a Unix console on a remote Unix computer. I (stupidly) didn't run it using nohup &, and now I need to close the local console.

Is there any way to have it keep running remotely after closing the local console?

0

4 Answers 4

11

If your shell is bash, they you can use disown. Ctrl-Z to suspend the process, then disown -h to make it not receive SIGHUP.

4
  • Brilliant solution. It worked :-)
    – Thrawn
    Mar 29, 2010 at 9:22
  • 3
    Just curious: as the process is suspended, shouldn't this eventually be followed with bg or something like that? Or does disown -h resume it as well?
    – Arjan
    Apr 25, 2010 at 15:13
  • Will this work if the process is running inside screen? I would like to continue running the process in my regular xterm instead.
    – voices
    Mar 19, 2016 at 4:22
  • IIRC once disowned it won't be connected to any terminal Mar 20, 2016 at 16:31
5

On Solaris 9, you can use nohup -p <pid> to nohup a running process. Here's an interesting explanation of the implementation. I don't know if this has been implemented on any other Unices.

1
  • nohup: invalid option -- p Doesn't work on gentoo, ubuntu or fedora (the unixes I tried this on), but thanks nevertheless :-) Good to know Solaris has it.
    – Thrawn
    Mar 26, 2010 at 18:37
2

Ctrl-Z to suspend the process, then bg to cause the program to go into the background and keep running until it completes.

3
  • Problem is that if I close the console, also the background processes will stop. I need something that detaches the process from the console, like nohup does, but after the process has started :-)
    – Thrawn
    Mar 26, 2010 at 12:58
  • And I don't think 'nohup bg &' will work either :-(
    – Thrawn
    Mar 26, 2010 at 13:19
  • 1
    I tried it on one of my systems and it kept running fine when I logged out (just used du / >> temp as the test progrm) but I understand being hesitant if you don't want to lose the program or it's results. Mar 26, 2010 at 23:17
2

If you can afford to stop the program and restart it before logging out, then stop it and restart it through screen, which is a must for anybody using remote connections to unix hosts.

4
  • 1
    I think the main problem here is precisely that he would like to not stop the program.
    – Gnoupi
    Mar 26, 2010 at 15:34
  • 1
    Yeah, I would like the program not to be stopped :-)
    – Thrawn
    Mar 26, 2010 at 18:32
  • I would highly suggest screen for future use of such a situation (I pretty much always have a screen session running on any system i have a sehll o). Mar 26, 2010 at 23:16
  • 1
    Several years later, I realized I was a fool not to be using screen :-)
    – Thrawn
    Aug 27, 2012 at 12:48

Not the answer you're looking for? Browse other questions tagged .