Keep a program running after closing a console, after the program has started

8

2

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?

Thrawn

Posted 2010-03-26T12:37:39.393

Reputation: 306

Question was closed 2012-08-05T18:43:08.043

Answers

12

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.

Douglas Leeder

Posted 2010-03-26T12:37:39.393

Reputation: 1 375

Brilliant solution. It worked :-) – Thrawn – 2010-03-29T09:22:33.927

3Just 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 – 2010-04-25T15:13:19.783

Will this work if the process is running inside screen? I would like to continue running the process in my regular xterm instead. – voices – 2016-03-19T04:22:16.280

IIRC once disowned it won't be connected to any terminal – Douglas Leeder – 2016-03-20T16:31:07.343

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.

coneslayer

Posted 2010-03-26T12:37:39.393

Reputation: 7 494

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 – 2010-03-26T18:37:11.393

2

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

Matrix Mole

Posted 2010-03-26T12:37:39.393

Reputation: 3 303

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 – 2010-03-26T12:58:56.337

And I don't think 'nohup bg &' will work either :-( – Thrawn – 2010-03-26T13:19:20.780

1I 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. – Matrix Mole – 2010-03-26T23:17:38.720

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.

geek

Posted 2010-03-26T12:37:39.393

Reputation: 7 120

1I think the main problem here is precisely that he would like to not stop the program. – Gnoupi – 2010-03-26T15:34:06.873

1Yeah, I would like the program not to be stopped :-) – Thrawn – 2010-03-26T18:32:42.123

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). – Matrix Mole – 2010-03-26T23:16:09.910

1Several years later, I realized I was a fool not to be using screen :-) – Thrawn – 2012-08-27T12:48:57.897